1

创建服务配置为:

<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);
                }
            }

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

在此处输入图像描述

但是当我尝试使用 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.
4

1 回答 1

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();
            }

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

于 2013-10-28T10:38:39.553 回答