即使机器服务在同一台机器上,WCF测试客户端也无法正常工作 [英] WCF Test Client not working even though machine service is on same machine

查看:68
本文介绍了即使机器服务在同一台机器上,WCF测试客户端也无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试WcfTestClient.exe提供我的Visual Studio来测试WCF服务(已将其设置为发现服务).该服务托管在WCF客户端所在的同一台计算机上,但是当我尝试添加服务"net.tcp://localhost:20000/Radio"时, 我收到以下错误:

错误:无法从net.tcp://localhost:25500/Radio获取元数据如果这是您具有的Windows(R)Communication Foundation服务访问,请检查是否已在指定的位置启用了元数据发布 地址.  有关启用元数据发布的帮助,请参阅MSDN文档,网址为http://go.microsoft.com/fwlink/?LinkId=65455.WS-MetadataExchange错误URI:net.tcp://localhost:25500/Radio  元数据包含参考 无法解决的问题:"net.tcp://localhost:25500/Radio".    <?xml version ="1.0" encoding ="utf-16"?< Fault xmlns ="http://www.w3.org/2003/05/soap-envelope"<代码>< Value>发件人< Value> ;< Subcode><值 xmlns:a ="http://www.w3.org/2005/08/addressing"> a:DestinationUnreachable</Value></Subcode></Code><原因<文本xml: lang ="en-GB">带有To'net.tcp://localhost:25500/Radio'的消息无法在 由于EndpointDispatcher上的AddressFilter不匹配,导致接收方无法接收.  检查发送方和接收方的EndpointAddress是否一致.


以下是我的服务的配置文件:

<? xml version = "1.0" encoding = "UTF-8" ?> < 配置> < announcementServiceEndpoint discoveryMulticastAddress = " soap.udp://239.255.255.250:9896" /> < serviceDiscoveryConfiguration discoveryCheckInterval = " 00:00:30" /> < system.serviceModel > < client > < 端点 名称 = " udpDiscoveryEndpoint" 种类 = "udpDiscoveryEndpoint" endpointConfiguration = " udpDiscoveryEndpointClient" /> < 端点 名称 = "dispatcherService" 地址 = "" 绑定 = "netTcpBinding" bindingConfiguration = "tcpBindingConfig" 合同 = "Server.DispatcherService.IDispatcherService" /> </客户端> < 服务> <!-用于接收的RadioSvc端点广播服务的命令-> < 服务 名称 = "Server.Radio.RadioService" behaviorConfiguration = " RadioServiceBehaviour" > < 主机> < baseAddresses > < 添加 baseAddress = " net.tcp://*:20000" /> </ baseAddresses > < 超时 openTimeout = " 00:01:00" closeTimeout = " 00:00:10" /> </主机> < 端点 地址 = "" 绑定 = "netTcpBinding" bindingConfiguration = "tcpBindingConfig" 合同 = "Server.Radio.IRadioService" behaviorConfiguration = " DynamicContactBehaviour" /> < 端点 种类 = "udpDiscoveryEndpoint" endpointConfiguration = " udpDiscoveryEndpointSvc" /> </服务> < 服务 名称 = " Radio.Web.RadioService" behaviorConfiguration = " RadioApiServiceBehaviour" > < 主机> < baseAddresses > < 添加 baseAddress = " http://*:20001" /> </ baseAddresses > < 超时 openTimeout = " 00:01:00" closeTimeout = " 00:00:10" /> </主机> < 端点 地址 = "mex" 绑定 = "mexHttpBinding" 合同 = "IMetadataExchange" /> < 端点 地址 = 网络" 绑定 = "basicHttpBinding" 名称 = 网络" 合同 = "Server.Radio.Web.IRadioService" bindingConfiguration = "basicHttpBinding" behaviorConfiguration = " WebEndpointBehaviour" /> </服务> </服务> < 绑定> < netTcpBinding > < 绑定 名称 = "tcpBindingConfig" receiveTimeout = " 00:10:00" sendTimeout = " 00:00:08" openTimeout = " 00:00:08" maxReceivedMessageSize = "4194304" maxBufferSize = " 4194304" > < 安全性 模式 = 无" /> </绑定> </ netTcpBinding > < basicHttpBinding > < 绑定 名称 = " basicHttpBinding" > < 安全性 模式 = 无" /> </绑定> </ basicHttpBinding > </绑定> < 行为> < serviceBehaviors > < 行为 名称 = " RadioServiceBehaviour" > <!-< monitoredRadioServiceBehaviour/>-> < standaloneRadioServiceBehaviour /> <!-< xslt serviceTransform ="RadioServiceTransforms.xslt"; callbackTransform =" RadioServiceCallbackTransforms.xslt"/>-> < serviceDiscovery > < announcementEndpoints > < 端点 种类 = " udpAnnouncementEndpoint" endpointConfiguration = " udpAnnouncementEndpointSettings" /> </ announcementEndpoints > </ serviceDiscovery > </行为> < 行为 名称 = " RadioApiServiceBehaviour" > < standaloneRadioServiceBehaviour /> < serviceMetadata httpGetEnabled = "True" /> < serviceDebug includeExceptionDetailInFaults = "true" /> </行为> </ serviceBehaviors > < endpointBehaviors > < 行为 名称 = " WebEndpointBehaviour" > < dynamicDataContractEndpointBehaviour assemblyQueryString = " * abc.dll" /> < sessionEndpointBehaviour /> </行为> < 行为 名称 = " DynamicContactBehaviour" > < dynamicDataContractEndpointBehaviour assemblyQueryString = " * abc.dll" /> </行为> </ endpointBehaviors span>> </行为> < standardEndpoints > < udpDiscoveryEndpoint > < standardEndpoint 名称 = " udpDiscoveryEndpointSvc" maxResponseDelay = " 00:00:00.800" multicastAddress = "soap.udp://239.255.255.250:9996" > < transportSettings timeToLive = "1" /> </ standardEndpoint > < standardEndpoint 名称 = " udpDiscoveryEndpointClient" maxResponseDelay = " 00:00:00.800" multicastAddress = " soap.udp://239.255.255.250:9896" > < transportSettings timeToLive = "1" /> </ standardEndpoint > </ udpDiscoveryEndpoint > < udpAnnouncementEndpoint > < standardEndpoint 名称 = " udpAnnouncementEndpointSettings" maxAnnouncementDelay = " 00:00:00.800" multicastAddress = "soap.udp://239.255.255.250:9996" > < transportSettings timeToLive = "1" /> </ standardEndpoint > </ udpAnnouncementEndpoint > </standardEndpoints> </system.serviceModel> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/> </startup> </configuration>

Can someone help what I am doing wrong. Do I need to change anything in my service config file? I am new to WCF and need load test this WCF service.

Please help !!!

谢谢

Kushal

解决方案

For adding service reference, you need to expose mex endpoint.

How did you host Service in code?

I suggest you try to modify the config like below:

    <system.serviceModel>
      
      <服务>
        <service name="Microsoft.Samples.Discovery.CalculatorService"
                 behaviorConfiguration="calculatorServiceBehavior">
          <端点地址="
                    binding ="netTcpBinding";
                    contract="Microsoft.Samples.Discovery.ICalculatorService"
                    behaviorConfiguration="endpointBehaviorConfiguration" />
          <!-- Add an UdpDiscoveryEndpoint over which the discovery service will listen for discovery request messages. -->
          <endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration"/>
          <endpoint address="mex" binding ="mexTcpBinding" contract ="IMetadataExchange"/
        <主机>
          < baseAddresses>
            <add baseAddress="net.tcp://*:20000"/>
            <add baseAddress="http://*:20001"/>
          </baseAddresses>
        </host>
        </service>
      </services>
      
      <行为>
        < serviceBehaviors>
          <behavior name="calculatorServiceBehavior">
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
            <!-- Add ServiceDiscoveryBehavior which enables discovery -->
            <serviceDiscovery>
              <!-- This section is used to specify where the announcement messages will be sent. If this section is not added, then announcements will not be sent. -->
              <announcementEndpoints>
                <endpoint kind="udpAnnouncementEndpoint"/>
              </announcementEndpoints>
            </serviceDiscovery>
          
          </行为>
        </serviceBehaviors>
        
        < endpointBehaviors>
          <behavior name="endpointBehaviorConfiguration">
            
            <endpointDiscovery>
              <!-- The endpoint discovery behavior can be used to enable or disable discovery for a particular endpoint as well as adding scopes. -->
              <scopes>
                <add scope="http://www.microsoft.com/building42/floor1"/>
                <add scope="ldap:///ou=engineering,o=exampleorg,c=us"/>
              </scopes>
            </endpointDiscovery>
            
          </行为>
        </endpointBehaviors>
        
      </行为>
      
      <standardEndpoints>
        <udpDiscoveryEndpoint>
          <!-- Specify the discovery protocol version and maxResponseDelay -->
          <standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11" maxResponseDelay="00:00:00.600" />
        </udpDiscoveryEndpoint>
      </standardEndpoints>
    
    </system.serviceModel>

And Host Code:

            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));
            serviceHost.Open();

Then, you could add service reference by "net.tcp://localhost:20000/mex"


Hi,

I am trying to WcfTestClient.exe provided my Visual Studio to test the WCF service (it is set as discovery service). This services is hosted on same machine where WCF client is residing, but when I try add service "net.tcp://localhost:20000/Radio" I get following error:

"Error: Cannot obtain Metadata from net.tcp://localhost:25500/Radio If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: net.tcp://localhost:25500/Radio    Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:25500/Radio'.    <?xml version="1.0" encoding="utf-16"?><Fault xmlns="http://www.w3.org/2003/05/soap-envelope"><Code><Value>Sender</Value><Subcode><Value xmlns:a="http://www.w3.org/2005/08/addressing">a:DestinationUnreachable</Value></Subcode></Code><Reason><Text xml:lang="en-GB">The message with To 'net.tcp://localhost:25500/Radio' cannot be processed at the receiver, due to an AddressFilter mismatch at the EndpointDispatcher.  Check that the sender and receiver's EndpointAddresses agree.</Text></Reason></Fault>"


Below is the config file for my service:

<?xml version="1.0" encoding="UTF-8"?> <configuration> <announcementServiceEndpoint discoveryMulticastAddress="soap.udp://239.255.255.250:9896" /> <serviceDiscoveryConfiguration discoveryCheckInterval="00:00:30" /> <system.serviceModel> <client> <endpoint name="udpDiscoveryEndpoint" kind="udpDiscoveryEndpoint" endpointConfiguration="udpDiscoveryEndpointClient" /> <endpoint name="dispatcherService" address="" binding="netTcpBinding" bindingConfiguration="tcpBindingConfig" contract="Server.DispatcherService.IDispatcherService" /> </client> <services> <!-- RadioSvc endpoint for receiving commands for the radio service --> <service name="Server.Radio.RadioService" behaviorConfiguration="RadioServiceBehaviour"> <host> <baseAddresses> <add baseAddress="net.tcp://*:20000" /> </baseAddresses> <timeouts openTimeout="00:01:00" closeTimeout="00:00:10" /> </host> <endpoint address="" binding="netTcpBinding" bindingConfiguration="tcpBindingConfig" contract="Server.Radio.IRadioService" behaviorConfiguration="DynamicContactBehaviour" /> <endpoint kind="udpDiscoveryEndpoint" endpointConfiguration="udpDiscoveryEndpointSvc" /> </service> <service name="Radio.Web.RadioService" behaviorConfiguration="RadioApiServiceBehaviour"> <host> <baseAddresses> <add baseAddress="http://*:20001" /> </baseAddresses> <timeouts openTimeout="00:01:00" closeTimeout="00:00:10" /> </host> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> <endpoint address="web" binding="basicHttpBinding" name="web" contract="Server.Radio.Web.IRadioService" bindingConfiguration="basicHttpBinding" behaviorConfiguration="WebEndpointBehaviour" /> </service> </services> <bindings> <netTcpBinding> <binding name="tcpBindingConfig" receiveTimeout="00:10:00" sendTimeout="00:00:08" openTimeout="00:00:08" maxReceivedMessageSize="4194304" maxBufferSize="4194304"> <security mode="None" /> </binding> </netTcpBinding> <basicHttpBinding> <binding name="basicHttpBinding"> <security mode="None" /> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="RadioServiceBehaviour"> <!--<monitoredRadioServiceBehaviour/>--> <standaloneRadioServiceBehaviour /> <!--<xslt serviceTransform="RadioServiceTransforms.xslt" callbackTransform="RadioServiceCallbackTransforms.xslt"/>--> <serviceDiscovery> <announcementEndpoints> <endpoint kind="udpAnnouncementEndpoint" endpointConfiguration="udpAnnouncementEndpointSettings" /> </announcementEndpoints> </serviceDiscovery> </behavior> <behavior name="RadioApiServiceBehaviour"> <standaloneRadioServiceBehaviour /> <serviceMetadata httpGetEnabled="True" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> <endpointBehaviors> <behavior name="WebEndpointBehaviour"> <dynamicDataContractEndpointBehaviour assemblyQueryString="*abc.dll" /> <sessionEndpointBehaviour /> </behavior> <behavior name="DynamicContactBehaviour"> <dynamicDataContractEndpointBehaviour assemblyQueryString="*abc.dll" /> </behavior> </endpointBehaviors> </behaviors> <standardEndpoints> <udpDiscoveryEndpoint> <standardEndpoint name="udpDiscoveryEndpointSvc" maxResponseDelay="00:00:00.800" multicastAddress="soap.udp://239.255.255.250:9996"> <transportSettings timeToLive="1" /> </standardEndpoint> <standardEndpoint name="udpDiscoveryEndpointClient" maxResponseDelay="00:00:00.800" multicastAddress="soap.udp://239.255.255.250:9896"> <transportSettings timeToLive="1" /> </standardEndpoint> </udpDiscoveryEndpoint> <udpAnnouncementEndpoint> <standardEndpoint name="udpAnnouncementEndpointSettings" maxAnnouncementDelay="00:00:00.800" multicastAddress="soap.udp://239.255.255.250:9996"> <transportSettings timeToLive="1" /> </standardEndpoint> </udpAnnouncementEndpoint> </standardEndpoints> </system.serviceModel> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /> </startup> </configuration>

Can someone help what I am doing wrong. Do I need to change anything in my service config file? I am new to WCF and need load test this WCF service.

Please help !!!

Thanks,

Kushal

解决方案

For adding service reference, you need to expose mex endpoint.

How did you host Service in code?

I suggest you try to modify the config like below:

    <system.serviceModel>
      
      <services>
        <service name="Microsoft.Samples.Discovery.CalculatorService"
                 behaviorConfiguration="calculatorServiceBehavior">
          <endpoint address=""
                    binding="netTcpBinding"
                    contract="Microsoft.Samples.Discovery.ICalculatorService"
                    behaviorConfiguration="endpointBehaviorConfiguration" />
          <!-- Add an UdpDiscoveryEndpoint over which the discovery service will listen for discovery request messages. -->
          <endpoint name="udpDiscovery" kind="udpDiscoveryEndpoint" endpointConfiguration="adhocDiscoveryEndpointConfiguration"/>
          <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://*:20000"/>
            <add baseAddress="http://*:20001"/>
          </baseAddresses>
        </host>
        </service>
      </services>
      
      <behaviors>      
        <serviceBehaviors>
          <behavior name="calculatorServiceBehavior">
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
            <!-- Add ServiceDiscoveryBehavior which enables discovery -->
            <serviceDiscovery>
              <!-- This section is used to specify where the announcement messages will be sent. If this section is not added, then announcements will not be sent. -->
              <announcementEndpoints>
                <endpoint kind="udpAnnouncementEndpoint"/>
              </announcementEndpoints>
            </serviceDiscovery>
          
          </behavior>
        </serviceBehaviors>
        
        <endpointBehaviors>
          <behavior name="endpointBehaviorConfiguration">
            
            <endpointDiscovery>
              <!-- The endpoint discovery behavior can be used to enable or disable discovery for a particular endpoint as well as adding scopes. -->
              <scopes>
                <add scope="http://www.microsoft.com/building42/floor1"/>
                <add scope="ldap:///ou=engineering,o=exampleorg,c=us"/>
              </scopes>
            </endpointDiscovery>
            
          </behavior>          
        </endpointBehaviors>
        
      </behaviors>
      
      <standardEndpoints>
        <udpDiscoveryEndpoint>
          <!-- Specify the discovery protocol version and maxResponseDelay -->
          <standardEndpoint name="adhocDiscoveryEndpointConfiguration" discoveryVersion="WSDiscovery11" maxResponseDelay="00:00:00.600" />  
        </udpDiscoveryEndpoint>
      </standardEndpoints>
    
    </system.serviceModel>

And Host Code:

            ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));
            serviceHost.Open();

Then, you could add service reference by "net.tcp://localhost:20000/mex"


这篇关于即使机器服务在同一台机器上,WCF测试客户端也无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆