[英]WCF Service Reference not working?
我已经创建了一个RESTful WCF服务(感谢StackOverflow)。 我创建了一个测试客户端,它是一个带有5个文本框和一个提交按钮的简单.aspx页面。 当我在文本框中输入数据并单击Submit按钮时,它将把数据提交到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>
我认为问题在于您根本没有为REST服务添加服务引用。 REST服务没有任何可用的元数据,因为没有用于描述它们的标准元数据格式。
能够添加服务引用的唯一原因是因为您留在服务上,该服务公开了它的SOAP定义。 因此,如果粘贴您的客户端配置,我确定该端点存在一个SOAP端点(wsHttpBinding或basicHttpBinding),因此您在进行调用时会收到有关mime类型不匹配的错误的原因。
如果要使用WCF从客户端调用REST服务,则需要在客户端和服务器之间共享合同定义,或者在客户端完全复制它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.