WCF ContractFilter mismatch - c#

I am hosting a WCF service on IIS. I can access the wsdl file with my browser. I can also add the Service Reference in Visual Studio for my client.
However, if I try to call Server.Test() an ActionNotSupportedException is thrown:
The message with Action 'http://tempuri.org/IWCFService/Test'
cannot be processed at the receiver, due to a ContractFilter mismatch
at the EndpointDispatcher. This may be because of either a contract
mismatch (mismatched Actions between sender and receiver) or a
binding/security mismatch between the sender and the receiver. Check
that sender and receiver have the same contract and the same binding
(including security requirements, e.g. Message, Transport, None).
I have two endpoints defined: One TCP.NET for the communication between the service and the client and one HTTP for metadata exchange.
Server Configuration (web.conf)
<services>
<service behaviorConfiguration="MyBehavior"
name="WCFServiceLibrary.Service.WCFService">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="MyServiceEndpoint"
name="MyServiceEndpoint"
contract="WCFServiceLibrary.Contract.IWCFService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Client Configuration (app.conf)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="MyServiceEndpoint">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.0.5:808/Service.svc" binding="netTcpBinding"
bindingConfiguration="MyServiceEndpoint" contract="ServiceReference.IWCFService"
name="MyServiceEndpoint" />
</client>
</system.serviceModel>
</configuration>
In IIS I have set net.tcp (808:*) binding as well as http (8080) binding.

Sorry, nothing jumps out at me, but if I may suggest you set up tracing on the client, it should tell you what the actual problem is:
http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx
Just a side note it seems to be the trend nowadays to reference the contract dll's in the client rather than use wsdl.

Shouldn't the baseaddress in web.config of the wcf service:
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>
be "net.tcp://..."
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>

A simple restart of the server did the trick!

Related

How to connect WCF Service to a UWP Appl In Another computer

I wanted to connect a WCF service to a UWP application. When it is on the same computer it works fine. But when I use it on another computer it doesn't work. It cannot be found when I tried to add it using Add Service Reference. I'm new to WCF. If you can give some explained details, I will really appreciate that.
The current configuration file in the WCF Service host (App.Config)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".
NETFramework,Version=v4.8" />
</startup>
<system.serviceModel>
<bindings></bindings>
<client></client>
<services>
<service name="PMService1.MainService"
behaviorConfiguration="mexBehavior">
<endpoint address="MainServiceReference"
binding="basicHttpBinding"
contract="PMService1.IMainService">
</endpoint>
<endpoint address="MainServiceReference"
binding="netTcpBinding"
contract="PMService1.IMainService">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://Pasan-Desktop:8086"/>
<add baseAddress="net.tcp://Pasan-Desktop:8090"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

NetTcp AND HTTP binding in WCF

I've been fiddling for two days now, trying to get my TCP endpoint working in my Wcf application.
I've hosted my Wcf app in IIS8 (NOT IIS Express), configured the website to enable net.tcp protocol listening on port 808.
But no matter what I do, I can't reach the TCP endpoint. The HTTP endpoint is working as intended.
Here's my Web.config:
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultHttpBinding" />
</basicHttpBinding>
<netTcpBinding>
<binding name="DefaultTCPBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="SimplBehavior" name="SimplWCF.WcfService">
<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
<endpoint address="local" binding="netTcpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultTCPBinding" name="localTcpBinding"/>
<!-- Used for connecting the service to CMS-->
<endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="public" binding="basicHttpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultHttpBinding" name="publicHttpBinding"/>
<!-- Used for connecting the webpages to the service-->
<host>
<baseAddresses>
<add baseAddress="http://localhost:50356/SimplWCF/" />
<add baseAddress="net.tcp://localhost:808/SimplWCF/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="SimplBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
<add binding="basicHttpBinding" scheme="http"/>
<add binding="netTcpBinding" scheme="net.tcp"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
I know that the HTTP endpoint doesn't work properly with httpGetEnabled="false", but right now I just need my TCP endpoint to work.
When I try to add a service reference in another project in Visual Studio (in the namespace as my WCF) I write the URL like this:
net.tcp://localhost:808/SimplWCF/WcfService.svc
But I'm not 100% sure this is the correct way of doing it.
Hope somebody can help me.
I finally got it working now!
I removed the relative address in the TCP endpoint, so that my config now looks like this: `
<services>
<service behaviorConfiguration="SimplBehavior" name="SimplWCF.WcfService">
<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
<endpoint address="" binding="netTcpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultTCPBinding" name="localTcpBinding"/>
<!-- Used for connecting the service to CMS-->
<endpoint address="mexhttp" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="public" binding="basicHttpBinding" contract="SimplWCF.IWcfService" bindingConfiguration="DefaultHttpBinding" name="publicHttpBinding"/>
<!-- Used for connecting the webpages to the service-->
<host>
<baseAddresses>
<add baseAddress="http://localhost:50356/SimplWCF/" />
<add baseAddress="net.tcp://localhost:808/SimplWCF/"/>
</baseAddresses>
</host>
</service>
</services>
Thank you for your time!

WCF service reject with error The server has rejected the client credentials

Following this guide i try to Host WCF service in a Windows Service Using TCP.
this works fine on my computer but when install this service in other computer in the same network got an error: The server has rejected the client credentials
I try to disable Firewall but still same error (and the service running...)
from the client side Add service reference works fine and recognize the service.
this is my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.0.100:8523/Service1 " />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
192.168.0.100 is the server machine IP address.
Try to use this config for tcp binding:
<bindings>
<netTcpBinding>
<binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>

WCF netTcpBinding - can't access Metadata

I am trying to run my service with the WCF Test Client using netTcpBinding (service runs fine with basicHTTP). I am getting the following error
Error: Cannot obtain Metadata from net.tcp://chatmesh/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. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: net.tcp://chatmesh/mex Metadata contains a reference that cannot be resolved: 'net.tcp://chatmesh/mex'. No DNS entries exist for host chatmesh. No such host is known
I don't see anything blatantly wrong that would cause the problem. Below is my app.config. Does anyone have any suggetions for me?
<?xml version="1.0" encoding="utf-8" ?>
<!--SERVICE App.config file-->
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="MachineLibrary.Machine1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NewBinding0"
name="" contract="MachineLibrary.IMachine1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://Chatmesh" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

Discover WCF hosted by Windows Service

In the solution, 4 projects : Business, the WCFService and the WCFServiceHost (a windows service) and a client
When I work in the solution, no problem, I can discover and create the proxy in the client.
When I install the host service, I start it but impossible to discover and create the proxy from visual studio with this : net.tcp://localhost:9100/MyApplicationWcf
Any idea ?
Thanks,
update #1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyApplicationWcf.MyClassWcf">
<endpoint address="net.tcp://localhost:9100/MyClassWcf"
binding="netTcpBinding"
bindingConfiguration=""
name="MyClassWcf_Tcp"
contract="MyApplicationWcf.MyClassWcf" />
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
</system.serviceModel>
</configuration>
If you want to discover the service over net.tcp, you will need to define a MEX endpoint (metadata exchange) that uses the mexTcpBinding.
<behaviors>
<serviceBehaviors>
<behavior name="MexBehavior" >
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="mexBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="YourServiceImpl"
behaviorConfiguration="MexBehavior">
<host>
<baseAddresses>
<add baseAddress ="net.tcp://localhost:9100/MyApplicationWcf/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
contract="IYourServiceContract" />
<endpoint address="mex"
binding="mexTcpBinding" bindingConfiguration="mexBinding"
contract="IMetadataExchange" />
</service>
</services>
Do you have that??
Check out: How to: Publish Metadata for a Service Using a Configuration File for more information.

Categories

Resources