this operation is not supported in the wcf test client because it uses type system.object[]

11,501

Solution 1

Since you're adding strings (ProcessName.ToString() - though ToString() is not required as ProcessName is already a string) to your service, you should define your method to return a List<string> instead of ArrayList.

This can be simplified to:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
class Windows_processes_Service:IWindows_processes_Service
{
    public List<string> GetRunningProcesses()
    {
        return Process.GetProcesses().Select(p => p.ProcessName).ToList();
    }
}

Solution 2

The problem is that ArrayList can be a list of anything (thus object[] in the error), and the test client can't handle that. While it is perfectly legal in WCF to return an array of arbitrary objects, you should consider returning the actual type that the client is interested in- in this case an array of String should do.

Also, for what it is worth, on modern (>1.1) versions of .NET, ArrayList is usually not used. The generic List<T> is usually more appropriate.

Share:
11,501
Enigma34
Author by

Enigma34

"Still searching for any key on my keyboard"

Updated on June 22, 2022

Comments

  • Enigma34
    Enigma34 almost 2 years

    hi while running my wcf service it gives me error "this operation is not supported in the wcf test client because it uses type system.object[]"

    enter image description here

    i m trying to retrieve the running process list.

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]
        class Windows_processes_Service:IWindows_processes_Service
        {
            ArrayList RunningProcesses_Name = new ArrayList();
            public ArrayList GetRunningProcesses()
            {
                Process[] processlist = Process.GetProcesses();
                foreach (Process nme_processes in processlist)
                {
                    RunningProcesses_Name.Add(nme_processes.ProcessName.ToString());
                }
                return RunningProcesses_Name;
            }
        }