Question

I have a WCF service that uses NetTcpBinding and I'd like to host it in a WPF application. The service seems to start correctly, but when I'm trying to get it's metadata using 'Add service reference' in visual studio I get this exception:

The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8000/Mandrake/mex'.

My service project's App.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
  <compilation debug="true" />
</system.web>
<system.serviceModel>
  <services>
    <service name="Mandrake.Service.OTAwareService">
      <endpoint address="OTService" binding="netTcpBinding" contract="Mandrake.Service.IOTAwareService">
        <identity>
          <dns value="localhost" />
        </identity>
      </endpoint>
      <endpoint name="MEX" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
      <host>
        <baseAddresses>
          <add baseAddress="net.tcp://localhost:8000/Mandrake/" />
        </baseAddresses>
      </host>
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <behavior>
        <serviceMetadata/>
        <serviceDebug includeExceptionDetailInFaults="False" />
      </behavior>
    </serviceBehaviors>
  </behaviors>
</system.serviceModel>

</configuration>

And the code in the hosting application:

Uri baseAddress = new Uri("net.tcp://localhost:8000/Mandrake");
ServiceHost host = new ServiceHost(typeof(OTAwareService), baseAddress);

try
{
    host.AddServiceEndpoint(typeof(IOTAwareService), new NetTcpBinding(), "OTService");

}
catch (CommunicationException e)
{
    Console.WriteLine(e.Message);
    host.Abort();
}

The solutions I found to the problem were mainly about adding the 'serviceMetaData' to the service config or providing a mex endpoint. Could you suggest something?

Edit:

Final config:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="NewBehavior0">
      <serviceMetadata />
      <serviceDebug includeExceptionDetailInFaults="True" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service name="Mandrake.Service.OTAwareService" behaviorConfiguration="NewBehavior0">
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8036/OTService"/>
      </baseAddresses>
    </host>

    <endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
    <endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />

  </service>
</services>
</system.serviceModel>

Hosting application:

host = new ServiceHost(typeof(OTAwareService));
host.Open();
Was it helpful?

Solution

I've managed to figure it out, after enabling the serviceDebug's includeExceptionDetailInFaults it was pretty clear.

Mandrake.Service.IOTCallback.Send operation references a message element [http://tempuri.org/:Send] that has already been exported from the Mandrake.Service.IOTAwareService.Send operation

So there was a Send(OTMessage) operation in the service contract and in the callback interface as well. A rather ugly mistake but I thought I would leave the solution here in case it helps anyone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top