无法从net.tcp://127.0.0.1ServiceName获取元数据

时间:2013-10-28 09:10:55

标签: c# .net wcf c#-4.0

将服务配置创建为:

<system.serviceModel>
       <services>
            <service behaviorConfiguration="DefaultBehaviour" 
                     name="DocumentManagementService.SharePointToSQL">
                 <endpoint address=""
                            binding="netTcpBinding" name="docManagementService"
                            contract="DocumentManagementService.ISharePointToSQL" />
                 <endpoint address="/mex" 
                           binding="mexTcpBinding"
                           contract="IMetadataExchange" />
                 <host>

                      <baseAddresses>
                           <add baseAddress="net.tcp://127.0.0.1/DocManagementService" />
                      </baseAddresses>
                 </host>
            </service>
       </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DefaultBehaviour">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceMetadata httpGetEnabled="true" httpGetUrl="http://127.0.0.1" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

并托管它:

using (ServiceHost serviceHost = new ServiceHost(typeof(SharePointToSQL)))
            {
                serviceHost.Open();

                foreach (var endPoints in serviceHost.Description.Endpoints)
                {
                    Console.WriteLine(endPoints.Address);
                }
            }

我可以通过控制台托管应用程序时看到端点地址:

enter image description here

但是当我尝试使用wcftestclient添加服务时,收到错误:

Error: 
Cannot obtain Metadata from net.tcp://127.0.0.1/DocManagementService/mex 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.

1 个答案:

答案 0 :(得分:0)

刚刚更新了托管应用程序的代码:

using (ServiceHost serviceHost = new ServiceHost(typeof(SharePointToSQL)))
            {
                serviceHost.Open();

                foreach (var endPoints in serviceHost.Description.Endpoints)
                {
                    Console.WriteLine(endPoints.Address);
                }

                Console.ReadKey();
                serviceHost.Close();
            }

使用块移动控制台读取和主机关闭并工作。其他明智的服务正在关闭,然后等待控制台读取。由于服务已经关闭,因此无法创建任何代理。