Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF NetTcpBinding with mex

Tags:

wcf

I'm trying to publish a wcf service using nettcpbinding. I want to publish metadata, using ?wsdl. I added the following line to the config file:

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

but I can't see the wsdl in my browser. what did I do wrong? Thanks.

Edit: Here is the relevant part of my config file:

<system.serviceModel>
   <services>
<service name="wcfcheck.service1" behaviorConfiguration="wcfcheck.Service1Behavior">
       <endpoint address="" binding="netTcpBinding" contract="wcfcheck.Iservice1"/>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
   </services>
<behaviors>
<serviceBehaviors>
  <behavior name="wcfcheck.Service1Behavior">
    <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
    <serviceDebug includeExceptionDetailInFaults="true"/>
  </behavior>
</serviceBehaviors>

I might not be accessing the right URL. I tried both http://localhost:51159/Service1.svc?wsdl and http://localhost:51159/Service1.svc/mex?wsdl, and without the '?wsdl'.

like image 220
Clangon Avatar asked Jul 15 '09 09:07

Clangon


People also ask

How can I call TCP net WCF service?

Address - where to call to - in your case net. tcp://localhost:25488/MyDataAccessService/MyFirstBindingAddress. Binding - what protocol and parameters to use (in your case: netTcpBinding ) Contract - the service contract (the public interface IMyDataAccessService ) to define the service methods and parameters needed.

What is Mex in WCF?

MEX endpoints expose metadata over configurable endpoints, and can use different types of transports, such as TCP or HTTP, and different types of security mechanisms. You said mex is configurable, but the wsdl is not.

What is netTcpBinding in WCF?

Remarks. This binding generates a run-time communication stack by default, which uses transport security, TCP for message delivery, and a binary message encoding. This binding is an appropriate Windows Communication Foundation (WCF) system-provided choice for communicating over an Intranet.


2 Answers

You need to use the <serviceMetadata> element.

    <behaviors>
      <serviceBehaviors>
      <behavior name="metadataSupport">
        <!-- Enables the IMetadataExchange endpoint in services that -->
        <!-- use "metadataSupport" in their behaviorConfiguration attribute. -->
        <!-- In addition, the httpGetEnabled and httpGetUrl attributes publish -->
        <!-- Service metadata for retrieval by HTTP/GET at the address -->
        <!-- "http://localhost:8080/SampleService?wsdl" -->
        <serviceMetadata httpGetEnabled="true" httpGetUrl=""/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
like image 141
John Saunders Avatar answered Sep 19 '22 08:09

John Saunders


You need to publish service metadata via http for wsdl. Add the following tag to the <system.serviceModel> tag of your config file

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

You will also need to specify an http address where the service metadata in wsdl will be available from. Add this to the <service> node of your config file :

<host>
  <baseAddresses>
    <add baseAddress="net.tcp://localhost:8001" />
    <add baseAddress="http://localhost:8000/Service1" />
  </baseAddresses>
</host>

Then if you go to http://localhost:8000/Service1?wsdl, you should see the wsdl for your service.

like image 34
Mehmet Aras Avatar answered Sep 18 '22 08:09

Mehmet Aras