对 WCF 服务感到困惑
本文关键字:WCF 服务 | 更新日期: 2023-09-27 18:37:12
我对这个WCF服务完全陌生,所以任何指南将不胜感激。
我收到了一个大型项目,其中包含检查某个设备的网络状态的代码。我的老板告诉我搜索TCPSocket创建并更改套接字上的某些选项。
检查网络状态的函数是ReqDDCNetworkStatus。当然,我搜索了代码的来源,并在我的服务参考下找到了这个接口:
public interface LGeDDC
{
[System.ServiceModel]
[System.ServiceModel.XmlSerializerFormatAttribute()]
[return: System.ServiceModel.MessageParameterAttribute(Name="result")]
string ReqDDCNetworkStatus(out string status);
}
这个文件被称为 References.cs我假设它是在 WSDL (SOAP) 文件上运行 svcutil 生成的.exe该文件,该文件用于在程序和相关设备之间进行通信。
这是具有被调用的实际函数的类:
namespace XrayEngines.DDCService
{
public partial class LGeDDCClient : System.ServiceModel.ClientBase<LGeDDC>, LGeDDC
{
public LGeDDCClient(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress)
{
}
public string ReqDDCNetworkStatus(out string status)
{
return base.Channel.ReqDDCNetworkStatus(out status);
}
}
}
因此,将按以下方式调用该函数:
try
{
for (int i = 0; i < p.Length; i++)
{
v = ddc.ReqDDCNetworkStatus(out r);
writeMessage("v:" + v + " , r:" + r);
}
}
catch (Exception e)
{
writeMessage("Network Exception Occurred: ."+e.ToString());
}
我迷路了。从字面上看,我没有看到任何在客户端和服务器之间建立连接的东西,但是该程序可以工作。如果有人能解释如何以这种方式建立连接,我将不胜感激。
神奇之处在于这两行:
public partial class LGeDDCClient : System.ServiceModel.ClientBase<LGeDDC>
和
return base.Channel.ReqDDCNetworkStatus(out status);
代理类继承自 ClientBase,ClientBase 是一个实现消息实际发送(执行远程调用)的类。
基
类System.ServiceModel.ClientBase负责所有连接工作。您只需设置服务的 URL 和更多参数,这通常使用配置文件完成。检查配置文件中的服务终结点、参数。