Web Services 内容类型text/html;响应消息的charset=UTF-8与绑定的内容类型(text/xml;字符集=utf-8)

k5hmc34c  于 2022-11-15  发布在  其他
关注(0)|答案(6)|浏览(265)

我创建了WCF服务,并使用独立的应用程序测试WCF客户端。我能够使用Internet Explorer查看此服务,也能够在Visual Studio中查看服务引用。以下是错误消息。
"The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."
你能告诉我哪里出了问题吗?

  • 谢谢-谢谢
4c8rllxm

4c8rllxm1#

因为返回的内容类型是text/html,所以我怀疑您的调用会导致WCF之外的服务器端错误(您将收到HTML错误页)。
尝试使用Web调试代理(如Fiddler)查看响应。
(Edit基于评论):
根据您的评论,我发现您的WCF托管在Sharepoint 2010下,位于一个经过表单验证的站点中。
您收到的错误是由于您的WCF客户端未使用SharePoint进行身份验证--它没有有效的身份验证Cookie。Sharepoint随后返回一个HTTP重定向到html页(login.aspx页);这不是WCF客户端所期望的。
要进一步操作,您必须从Sharepoint获取身份验证Cookie(请参阅Authentication Web Service)并将其传递到WCF客户端。
(更新编辑):
错误:该站点正在使用基于声明的身份验证。
虽然这不一定是由于Cookie或窗体身份验证造成的,但对所提供错误消息的解释仍然相同。身份验证问题导致重定向到HTML页,WCF客户端不处理该问题。

m4pnthwp

m4pnthwp2#

这可能会有帮助,请检查ISS 7中的URL重写规则。如果您没有正确配置规则,则会出现此问题。

pkmbmrz7

pkmbmrz73#

听起来你的应用程序需要XML,但是接收的是纯文本。你传入的是什么类型的对象?

vql8enpb

vql8enpb4#

text/html是SOAP 1.1标头,内容类型:application/soap+xml is SOAP 1.2请验证绑定并返回标头它应该与1.1或1.2相同

pcrecxhr

pcrecxhr5#

将以下代码添加到web.config服务器项目中。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding_IService">
      <security mode="Transport">
        <transport clientCredentialType="None" proxyCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

<services>
  <service name="Service">
    <endpoint address="" name="BasicHttpBinding_IService"
              binding="basicHttpBinding"
              bindingConfiguration="basicHttpBinding_IService"
              contract="IService" />
  </service>

然后更新客户端Web服务,更新后,将对web.config进行以下更改

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService">
      <security mode="Transport" />
    </binding>
  </basicHttpBinding>
</bindings>

  <endpoint address="https://www.mywebsite.com/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
    contract="Service.IService" name="BasicHttpBinding_IService" />

我希望能帮上忙

p5fdfcr1

p5fdfcr16#

调用BookingCommit服务时,NavitaireProvider中出现此错误(WCF服务引用)
因此,当我们获取缓存代理对象时,它还将检索旧的SigninToken,该令牌可能仍无法持久保存,因此无法进行身份验证
因此,作为一种解决方案,我调用了LogonService,当我获得此异常以检索新令牌时

相关问题