WCF Service Reference not working?
I have created a RESTful WCF service (thanks to StackOverflow). I have created a test client, it's a simple .aspx page with 5 textboxes and a submit button. When I enter the data into the textboxes and click on the Submit button it will submit the data to the WCF service.
My WCF service is running under Visual Studio development server and it worked fine, I am able to send data successfully to WCF service. Today I deployed this WCF Service on my local IIS. When I am trying to reference the Service URL in client application (.aspx page), I am getting this error.
"Metadata contains a reference that cannot be resolved. The client and service bindings may be mismatched. Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml;"
Any idea what the problem could be? Here is my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel> 开发者_运维百科
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="RESTService1">
<endpoint address="http://localhost:420/WCFRESTService100/RESTService1.svc" binding="webHttpBinding" name="MainHttpPoint" contract="RESTService1" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:420/WCFRESTService100/RESTService1.svc" />
</baseAddresses>
</host>
</service>
</services>
<!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>-->
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
I think the problem is that you've added a service reference at all for a REST service. REST services do not have any metadata available because there is no standard metadata format for describing them.
The only reason you were able to add a service reference is because you left on your service which exposed a SOAP definition for it. So, if you paste your client config I'm sure the endpoint there is a SOAP endpoint (wsHttpBinding or basicHttpBinding) hence the reason you get the error about the mime-type mismatch when you make the call.
If you want to call the REST service from the client using WCF, you would either need to share the contract definition between client and server or completely duplicate it at the client.
精彩评论