This operation is not supported in the wcf test client because the type system.object [] is used.

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

enter image description here

im trying to get a list of running processes.

[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; } } 
+7
source share
2 answers

Since you are adding strings ( ProcessName.ToString() - although ToString() not required since ProcessName already a string ) for your service, you must define your method to return List<string> instead of ArrayList .

This can be simplified:

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

The problem is that an ArrayList may be a list of something (thus object[] in error), and the test client cannot handle it. Although it is perfectly legal for WCF to return an array of arbitrary objects, you should consider returning the actual type of interest to the client, in which case the String array should be executed.

In addition, for what costs, on modern (> 1.1) versions of .NET, ArrayList usually not used. Usually a generic List<T> more suitable.

+3
source

All Articles