WCF 服务参考不起作用?
我创建了一个 RESTful WCF 服务(感谢 StackOverflow)。我创建了一个测试客户端,它是一个简单的 .aspx 页面,带有 5 个文本框和一个提交按钮。当我在文本框中输入数据并单击“提交”按钮时,它将提交数据 到 WCF 服务。
我的 WCF 服务在 Visual Studio 开发服务器下运行,工作正常,我能够成功地将数据发送到 WCF 服务。今天我在本地 IIS 上部署了这个 WCF 服务。当我尝试在客户端应用程序(.aspx 页面)中引用服务 URL 时,出现此错误。
“元数据包含无法解析的引用。客户端和 服务绑定可能不匹配。无法处理该消息,因为 内容类型'application/soap+xml; charset=utf-8' 不是 预期类型 'text/xml;"
知道问题可能是什么吗?这是我的 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 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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您已经为 REST 服务添加了服务引用。 REST 服务没有任何可用的元数据,因为没有标准的元数据格式来描述它们。
您能够添加服务引用的唯一原因是您保留了为其公开 SOAP 定义的服务。因此,如果您粘贴客户端配置,我确信端点有一个 SOAP 端点(wsHttpBinding 或 basicHttpBinding),这就是您在进行调用时收到有关 mime 类型不匹配的错误的原因。
如果要使用 WCF 从客户端调用 REST 服务,则需要在客户端和服务器之间共享协定定义,或者在客户端完全复制它。
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.