Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WCF从其他类返回列表_C#_Wcf - Fatal编程技术网

C# 使用WCF从其他类返回列表

C# 使用WCF从其他类返回列表,c#,wcf,C#,Wcf,我正在创建一个WCF服务,它将允许对我的一个服务器应用程序进行远程管理 这个服务器应用程序包含一个连接的客户端列表(它们的地址信息),我希望使用WCF获得这些客户端 当我创建服务时,它创建了两个文件、一个类和该类的接口 生成的类我无法使用,因为它不包含列表,我的服务器应用程序的“服务器”类就是包含此列表的类 因此,我在我的“服务器”类中实现了这个接口,并添加了相关代码以返回客户机的地址列表 这是我第一次使用WCF,我觉得我做错了 如上所述,访问不属于服务一部分的另一个类中的列表的正确方法是什么

我正在创建一个WCF服务,它将允许对我的一个服务器应用程序进行远程管理

这个服务器应用程序包含一个连接的客户端列表(它们的地址信息),我希望使用WCF获得这些客户端

当我创建服务时,它创建了两个文件、一个类和该类的接口

生成的类我无法使用,因为它不包含列表,我的服务器应用程序的“服务器”类就是包含此列表的类

因此,我在我的“服务器”类中实现了这个接口,并添加了相关代码以返回客户机的地址列表

这是我第一次使用WCF,我觉得我做错了

如上所述,访问不属于服务一部分的另一个类中的列表的正确方法是什么

谢谢

我是如何实现该服务的:

class MyServer : IMonitorService
{
ServiceHost myHost = new ServiceHost(typeof(MyServer));

myHost.Open();
我如何主持服务:

class MyServer : IMonitorService
{
ServiceHost myHost = new ServiceHost(typeof(MyServer));

myHost.Open();
GetClientList:

    public List<string> GetClientList()
    {
        List<string> clientStringList = new List<string>();
        lock (ClientList) 
        {
            foreach (ClientHandle client in ClientList)
            {
                clientStringList.Add(client.ClientAddress);
            }
        }
        return clientStringList;
    }
public List GetClientList()
{
List clientStringList=新列表();
锁定(客户端列表)
{
foreach(ClientList中的ClientHandle客户端)
{
clientStringList.Add(client.ClientAddress);
}
}
返回clientStringList;
}
在您的界面中

List<myClass> send();
List send();
在你们班上:

List<myClass> send(){

List<myClass> myList = new List<myClass>();

 return myList;
列表发送(){
List myList=新列表();
返回myList;
}

通过这种方式,您可以使用wcf服务返回任何类列表