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[]"
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;
}
}
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.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With