netTCP绑定和自托管的问题

时间:2012-04-05 09:06:34

标签: wcf nettcpbinding self-hosting

我在网上搜索过但我无法找到解决问题的方法。

我使用nettcpbinding在XP上自行托管我的服务。配置文件如下:

<system.serviceModel>

    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
        logMessagesAtTransportLevel="true" />
    </diagnostics>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" />

    <services>       
 <service behaviorConfiguration="behaviorconfig"
        name="myservice">
         <host>
          <baseAddresses>
            <add baseAddress="net.tcp://10.1.3.186:8001/myService" />
          </baseAddresses>
        </host>
        <endpoint address=""
               binding="netTcpBinding"
               bindingConfiguration="BindingConfiguration"
               contract="xxx.ISomeService" />

        <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />       
      </service>
 </services>
    <bindings>
           <netTcpBinding>
        <binding name="BindingConfiguration" receiveTimeout="10:00:00"
          sendTimeout="10:00:00" maxBufferSize="65536" maxReceivedMessageSize="65536"
          transferMode="Streamed">
          <readerQuotas maxDepth="65536" maxStringContentLength="65536"
            maxArrayLength="65536" maxBytesPerRead="97108864" maxNameTableCharCount="65536" />
          <security mode="None" />
        </binding>
      </netTcpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorconfig">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>

      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

并且自我主机代码是

Uri tcpUrl = new Uri("net.tcp://10.1.3.186:8001/myService");
            //Create ServiceHost
            ServiceHost host
            = new ServiceHost(typeof(xxx.SomeService), tcpUrl);
            //Add a service endpoint
            host.AddServiceEndpoint(typeof(xxx.ISomeService)
            , new NetTcpBinding(), "");
            //Enable metadata exchange

            ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
            smb.HttpGetEnabled = false;
            host.Description.Behaviors.Add(smb);
            //Start the Service
            host.Open();

当我尝试添加服务引用时,我收到错误错误:无法从net.tcp获取元数据://10.1.3.186:8001 / myService / mex

这里有什么问题?

2 个答案:

答案 0 :(得分:3)

看起来你错过了mex端点:

host.AddServiceEndpoint(typeof(IMetadataExchange),MetadataExchangeBindings.CreateMexTcpBinding(),“mex”);

稍作修改以澄清: 需要mex端点,以便可以交换有关服务上可用内容的信息。除了主TCP侦听器之外,还要添加它。使用基于http的服务(wsdl等)

时会自动添加

答案 1 :(得分:0)

检查这些:

  1. 非Http激活:http://msdn.microsoft.com/en-us/library/ms731053(VS.100).aspx
  2. 检查Windows服务 Net.Tcp侦听器适配器是否正在运行