1

Create the Service Configuration as:

<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>

and to Host It:

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

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

I am able to see the endpoint address while hosting the application through console:

enter image description here

But when I am trying to add the service using wcftestclient , getting the error:

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

Console Read と Host Close を using ブロック内に移動し、機能しました。他の賢明なサービスは閉じていて、コンソールの read を待っていました。また、サービスが既にシャットダウンされているため、プロキシを作成できませんでした。

于 2013-10-28T10:38:39.553 に答える