开发者

WCF- Meta Data Exchange Configuration

I have defined two endpoints in my App.Config file as

 <system.serviceModel>
    <services>
      <service 
              name="HostDirectAddress.ITestService" 
              behaviorConfiguration="behaviorConfig">

      <endpoint 
                开发者_如何学Goaddress="net.tcp://localhost:9000/ITestService"
                binding="netTcpBinding"
                contract="HostDirectAddress.ITestServiceContract"/>

    <endpoint
                address="http://localhost:9000/mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />

    </service>
   </services>
        <behaviors>
           <serviceBehaviors>
            <behavior name="behaviorConfig">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="True"/>
            </behavior>
          </serviceBehaviors>
 </behaviors>
</system.serviceModel>

My client calls

static void Main(string[] args)
{
      ServiceHost host = 
        new ServiceHost(typeof(HostDirectAddress.ITestService));
      host.Open();
      Console.WriteLine("....Service is Ready to Consume...");
      Console.ReadLine();
 }

I received the following error when i try to launch the host

The HttpGetEnabled property of ServiceMetadataBehavior is set to true and the HttpGetUrl property is a relative address, but there is no http base address. Either supply an http base address or set HttpGetUrl to an absolute address.

How to fix it?


The error message tells you how to fix it!

1) Add a base address

<service 
    name="HostDirectAddress.ITestService" 
    behaviorConfiguration="behaviorConfig">
    <host>
       <baseAddresses>
          <add baseAddress="http://localhost:9000/" />
       </baseAddresses>
    </host>
    <endpoint
            address="mex"
            binding="mexHttpBinding"
            contract="IMetadataExchange" />

OR:

2) Define a fixed and complete HTTP address in your service behavior:

<behavior name="behaviorConfig">
    <serviceMetadata 
        httpGetEnabled="true"
        httpGetUrl="http://localhost:9000/mex" />
    <serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>

Do one or the other - and things should work just fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜