发现Windows服务托管的WCF

时间:2010-11-25 08:31:56

标签: c# .net wcf

在解决方案中,有4个项目:Business,WCFService和WCFServiceHost(一个Windows服务)和一个客户端

当我在解决方案中工作时没问题,我可以在客户端中发现并创建代理。

当我安装主机服务时,我启动它但不可能从visual studio中发现并创建代理:net.tcp:// localhost:9100 / MyApplicationWcf

有什么想法吗?

谢谢,

更新#1

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="MyApplicationWcf.MyClassWcf">
        <endpoint address="net.tcp://localhost:9100/MyClassWcf"
                  binding="netTcpBinding"
                  bindingConfiguration=""
                  name="MyClassWcf_Tcp"
                  contract="MyApplicationWcf.MyClassWcf" />

        <endpoint name="mexHttpBinding"
                  contract="IMetadataExchange"
                  binding="mexHttpBinding"
                  address="mex" />
      </service>       
    </services>    
  </system.serviceModel>
</configuration>

1 个答案:

答案 0 :(得分:2)

如果要通过net.tcp发现服务,则需要定义使用mexTcpBinding的MEX端点(元数据交换)。

<behaviors>
   <serviceBehaviors>
      <behavior name="MexBehavior" >
         <serviceMetadata/>                             
      </behavior>
   </serviceBehaviors>
</behaviors>    
<bindings>
   <netTcpBinding>
      <binding name="mexBinding" portSharingEnabled="true">
          <security mode="None"></security>
      </binding>
   </netTcpBinding>       
</bindings>
<services>
   <service name="YourServiceImpl"
            behaviorConfiguration="MexBehavior">                 
      <host>
         <baseAddresses>
            <add baseAddress ="net.tcp://localhost:9100/MyApplicationWcf/"/>
         </baseAddresses>
      </host>
      <endpoint address=""
                binding="netTcpBinding"
                contract="IYourServiceContract" />
      <endpoint address="mex"
                binding="mexTcpBinding" bindingConfiguration="mexBinding" 
                contract="IMetadataExchange"   />
   </service>
</services>
你有吗?

查看:How to: Publish Metadata for a Service Using a Configuration File了解详情。