创建服务配置为:
<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.