1

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

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

这里有什么问题?

4

2 回答 2

3

看起来您缺少 mex 端点:

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

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

于 2012-04-06T16:53:20.157 回答
0

检查这些:

  1. 非Http激活:http: //msdn.microsoft.com/en-us/library/ms731053 (VS.100).aspx
  2. 检查 Windows Service Net.Tcp 侦听器适配器是否正在运行
于 2012-04-05T09:51:42.367 回答