小编Eno*_*pal的帖子

是否可以使WcfTestClient适用于自定义传输通道?

目标

我希望能够通过WCF在我正在设计的托管框架内托管和连接到vanilla套接字服务器.我希望能够使用WCF来编码今天必须由套接字程序员手动管理的传输和协议通信.这将允许我与Linux服务器守护程序的最终互操作性,除了传统的套接字和专有协议之外什么也不暴露.我只对此时通常使用WcfTestClient验证传输通道层感兴趣.我的理解是WcfTestClient不支持复杂的服务方法.

有人认为可以使WcfTestClient适用于自定义传输通道吗? 能够通常使用此客户端来测试任意数量的自定义传输通道将是非常好的.

概观

我正在努力了解Windows SDK中包含的WCF Udp示例,该示例通常位于C:\ Program Files\Microsoft SDKs\Windows\v6.1\Samples\WCFSamples\TechnologySamples\Extensibility\Transport\Udp\CS,假设WCFSamples.zip文件是从Samples目录中完全解压缩的.

这是我到目前为止采取的步骤:

  • (成功):在Visual Studio 2008中成功运行解决方案的服务和客户端.

  • (成功):使用通常位于C:\ Program Files\Microsoft Visual Studio 9.0\Common7\IDE的WcfTestClient连接到MEX端点

  • (失败):使用WcfTestClient尝试从ICalculatorContract或IDatagramContract服务合同执行方法.

例如,当我执行Hello()方法时,我收到以下错误:

友情致辞:

无法调用该服务.可能的原因:服务离线或无法访问; 客户端配置与代理不匹配; 现有代理无效.有关更多详细信息,请参阅堆栈跟踪.您可以尝试通过启动新代理,还原到默认配置或刷新服务来进行恢复.

错误详情:

具有合同"IDatagramContract"的ServiceEndpoint上的CustomBinding缺少TransportBindingElement.每个绑定必须至少有一个派生自TransportBindingElement的绑定元素.在System.ServiceModel.Channels.Binding.EnsureInvariants(字符串contractName)在System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()在System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint serviceEndpoint)在System.ServiceModel.ChannelFactory.CreateFactory()在System.ServiceModel.ChannelFactory.OnOpening()处于System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)的System.ServiceModel.ChannelFactory.EnsureOpened()处于System.ServiceModel.ChannelFactory1.CreateChannel(EndpointAddress address, Uri via) at System.ServiceModel.ChannelFactory1.CreateChannel()在System.ServiceModel.ClientBase 1.CreateChannel() at System.ServiceModel.ClientBase1.CreateChannelInternal()在System.ServiceModel.ClientBase`1.get_Channel()在DatagramContractClient.Hello()

了解客户端错误

在UdpTransport项目中定义的UdpTransportBindingElement肯定是从TransportBindingElement派生的,如下所示,所以我认为WcfTestClient配置文件中必定缺少某些内容和/或可能我必须以某种方式为测试客户端提供更多信息.我尝试将Udp解决方案的客户端项目的System.ServiceModel部分复制到WcfTestClient的配置文件中,以及将传输程序集dll复制到与测试客户端相同的文件夹中,但是我收到了同样的错误.

我的理解是MEX端点应该足以获得调用服务上的简单方法所需的信息.当然,我理解这个故事可能还有更多,考虑到我正在努力创建一个旨在测试开箱即用传输通道的客户端与自定义传输通道一起工作.

/// <summary>
/// Udp Binding Element.  
/// Used to configure and construct Udp ChannelFactories and ChannelListeners.
/// </summary>
public class UdpTransportBindingElement 
    : TransportBindingElement // to signal that we're a transport
    , IPolicyExportExtension // for policy …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf interface wcf-binding

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

.net ×1

c# ×1

interface ×1

wcf ×1

wcf-binding ×1