I have a WCF web service I am tryiong to publish to IIS. I can view the wsdl fine but cannot add the service in Visual Studio 2010 via the Add Service Reference menu. I get the following error:
Metadata contains a reference that cannot be resolved: 'http://localhost:4567/Service.svc?wsdl'.
The WSDL document contains links that could not be resolved.
There was an error downloading 'http://localhost:4567/Service.svc?xsd=xsd0'.
The underlying connection was closed: An unexpected error occurred on a receive.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
Metadata contains a reference that cannot be resolved: 'http://localhost:4567/Service.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:4567/Service.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
I works great locally but not if published to IIS.
Does anyone know what is causing this problem? Here is my web.config, I am new to WCF so might have missed something out, thanks:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>
</connectionStrings>
</configuration>
I truly wish Microsoft would put better diagnostics in place to give us more targeted information on WCF configuration errors either at at build or runtime - I don't care which, but it has wasted so many hours of development time over the years it's unreal.
</rant>
For me, this ridiculously generic error's cause was this:
<endpoint address="mexTcp" binding="mexTcpBinding" contract="IMetadataExchange"/>
Should have been this:
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
Two hours of fart-arsing around trying to enable Net.Tcp for something that could have easily been highlighted in the IDE. Two hours!!!
As this is one of the first posts google shows up for this error, I want to participate with my solution:
I got a similar error while changing code in a system that was working well, but updating the reference on my development system failed. The reference is located inside a silverlight project and is related to a WCF integrated in the surrounding website (standard configuration I guess).
My error message included
"WCF Metadata contains a reference that cannot be resolved: 'Some funny path'. The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8)."
My website uses authorization roles, thats where the problem/solution was based. For updating the service reference I had to allow all users:
<?xml version="1.0"?>
<configuration>
<system.web>
<!--<authorization>
<allow users="*"/>
</authorization>-->
<authorization>
<deny users="?"/>
<allow roles="role-1,role-2"/>
<deny users="*"/>
</authorization>
</system.web>
</configuration>
Check the answer here MSDN forum
When you define a net tcp protocol you need to ensure you are using
IMetadataExchange
contract defined in an endpoint contract. The service behaviour for this also needs to contain the<serviceMetadata />
tag. From what i have understood, this is pretty much boilerplate code for your config if you are wanting to host and generate proxys / discover in VS.
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With