【问题标题】:Problems with netTCP Binding and Self hostingnetTCP 绑定和自托管的问题
【发布时间】:2012-04-05 09:06:34
【问题描述】:

我已经在网上搜索过,但找不到解决问题的方法。

我使用 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>

并且selfhost代码是

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 获取元数据

这里有什么问题?

【问题讨论】:

  • 您的 service 元素的 name 属性为 myservice 应该是 xxx.myservice (xxx 是命名空间)

标签: wcf nettcpbinding self-hosting


【解决方案1】:

看起来您缺少 mex 端点:

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

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

【讨论】:

    【解决方案2】:

    检查这些:

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

    【讨论】:

      猜你喜欢
      • 2016-10-11
      • 1970-01-01
      • 2012-01-18
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 2015-03-19
      • 1970-01-01
      • 2014-12-12
      相关资源
      最近更新 更多