【发布时间】:2015-10-20 16:20:31
【问题描述】:
我正在尝试连接我的一种方法,以便在将获取请求发送到适当的端点后调用。篡改我的 web.config 时,我为我的行为分配了一个名称,我收到以下错误。
'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
不知道为什么只为我的行为分配一个属性会引发此错误。
<system.serviceModel>
<services>
<service name="Developer1.Core.Service.Developer1Service"
bindingConfiguration="myConfiguration" >
<endpoint
address="" behaviorConfiguration="webBehavior"
binding="webHttpBinding"
contract="Developer1.Core.ServiceContracts.IDeveloper1Service" />
<endpoint
address="mex" binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="myConfiguration">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
似乎当我带走并且没有名称属性时,错误消失了。有什么想法吗?
解决了!!!
我解决了这个问题,似乎我必须在服务库而不是应用程序中做我正在做的事情。所以现在我正在使用我的 wcf 库处理 REST,而其他方法在我的 WCF 应用程序中处理。似乎应用程序配置和网络配置在某种程度上有所不同。然后我转到解决方案属性并选择一次启动多个项目。现在我可以在库中使用 get 请求访问方法,并且应用程序运行所有其他不处理 HTTP 协议的方法。我的解决方案中有一个 WCF 库和 WCF 应用程序。应用程序使用 web.config,库使用 app.config。按照这篇文章http://weblogs.asp.net/kiyoshi/wcf-using-webhttpbinding-for-rest-services 使用应用程序配置。然后,我的 WCF 应用程序从我的库中的服务文件继承,并且不包含任何额外的服务方法,它只是运行我的 WCF 库中的方法。但是库被设置为处理 HTTP 请求。可能不是正确的解决方案,但它对我有用。
【问题讨论】:
-
在您显示的代码/配置中没有任何问题指向您。你能告诉我们请求/客户端的详细信息吗?
-
我有理由怀疑,因为您拥有基于 Rest 的
webHttpBinding。不知何故,您的客户正在向Rest端点发送Soap消息。错误消息说明了一切。 -
但是有很多文章展示了如何使 REST 与 wcf 服务中的某些方法一起工作。我是不是配置错了?
标签: web-services wcf utf-8 web-config