1

I am new to WCF and I am trying to use netTcpBinding

My question is how I can publish metadata?

When I use tcp address as base address it gives this error

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

I need to publish metadata. But how can I do this when using this

<baseAddresses>
        <add baseAddress = "net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/" />

</baseAddresses>

And my end point is like this

 <endpoint address ="" binding="netTcpBinding" contract="tester.IService1">

When I changed my endpoint for metadata like this

   <endpoint address="mex" binding="wsHttpBinding" contract="IMetadataExchange"/>

Now it giving me this error

 Please try changing the HTTP port to 8732 or running as Administrator.
user786
  • 3,902
  • 4
  • 40
  • 72

3 Answers3

0

In your serviceBehaviors you specified following behavior:

<serviceMetadata httpGetEnabled=True/>

Since you made up your mind to expose metadata with HTTP protocol, WCF by default seeks in baseAddresses for HTTP equivalent. Alas, you have not specified such so error occures. Solution is to either give up on exposing metadata on HTTP or add another baseAddress, this time with http protocol or set HttpGetUrl with absolute address.

Maximus
  • 3,458
  • 3
  • 16
  • 27
0

Did you host it on IIS? If so, you need to enable WAS - Windows Activation Service. Please refer: what is the diffence between WAS and IIS?

If not then give address reference in your configuration setting.

Community
  • 1
  • 1
Aj B
  • 1
  • 1
0

Since this is the first resulted in google search when I search for publish metadata via nettcp binding.So thought to answer one more time.Suppose below is the app.config file.

<endpoint address ="" binding="netTcpBinding" contract="tester.IService1">
<baseAddresses>
<add baseAddress = "net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/" />

Step 1:Define your nettcp binding via endpoint and also the baseaddress where it need to be hosted.So it will be

<services>
    <service name="tester.Service1">
    <endpoint address ="" binding="netTcpBinding" contract="tester.IService></endpoint>
<host>
  <baseAddresses>
    <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/"/>
  </baseAddresses>
</host>
</service>

Step 2:Enable nettcp metadata endpoint.

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>

Step 3:After enabling the nettcp metadata endpoint make it discoverable to the outside world,i.e by implementing IMetadataExchange contract which is done by through serviceMetadata tag.

 <behaviors>
    <serviceBehaviors>
      <behavior name="Default">
        <serviceMetadata httpGetEnabled="false" httpGetUrl=""/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  </services>

Step 4:Now relate and bind the service behavior to the exposed service.

    <services>
            <service name="tester.Service1" behaviorConfiguration="Default">
            <endpoint address ="" binding="netTcpBinding" contract="tester.IService></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/"/>
          </baseAddresses>
        </host>
        </service>
        </services>

Now you can check through the WCFtestclient.exe through VS command prompt and browse through net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/ or browse this address and service nettcp metadata will be discovered.

Note: If you want the metadata to be discovered through http(browser) need wsdl also then below modification is required .

1.Add a http metadata endpoint

 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

2.Provide its contract implementation and make httpGetEnabled to true to make the service discoverable .

<behaviors>
        <serviceBehaviors>
          <behavior name="Default">
            <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
          </behavior>
        </serviceBehaviors>
</behaviors>

So final endpoints definition will be

    <services>
    <service name="tester.Service1" behaviorConfiguration="Default">
    <endpoint address ="" binding="netTcpBinding" contract="tester.IService></endpoint>
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
 <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      <host>
      <baseAddresses>
      <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/tester/Service1/"/>
     <add  baseAddress="http://localhost:8732/Design_Time_Addresses/tester/Service1/"/>
       </baseAddresses>
       </host>
 </service>
</services>
Hameed Syed
  • 3,939
  • 2
  • 21
  • 31