【问题标题】:WCF with non WCF Client带有非 WCF 客户端的 WCF
【发布时间】:2010-02-19 19:05:18
【问题描述】:

从客户端使用我的 WCF 服务时,我收到以下错误消息。问题是当我能够从 Windows 客户端或控制台应用程序轻松运行代码时。只是不是来自我的网络应用程序。

System.InvalidOperationException was unhandled by user code
  Message="Client found response content type of 
  'multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:28551dc8-55af-4ec9-a9dc-169075c7f50a+id=6";start-info="text/xml"', but expected 'text/xml'. 
  The request failed with the error message: --  
  --uuid:28551dc8-55af-4ec9-a9dc-169075c7f50a+id=6 Content-ID: <http://tempuri.org/0> Content-Transfer-Encoding: 8bit Content-Type: application/xop+xml;charset=utf-8;type="text/xml"  
  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode><faultstring xml:lang="en-US">PrintOut3: Conversion failed</faultstring><detail><ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><HelpLink i:nil="true"/><InnerException i:nil="true"/>

这是我的 WCF 服务绑定配置

<basicHttpBinding>
  <binding name="BasicHttpBinding_IMakePDFService" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    allowCookies="false" bypassProxyOnLocal="false"
    hostNameComparisonMode="StrongWildcard"
    maxBufferSize="65536" maxBufferPoolSize="524288" 
    maxReceivedMessageSize="65536" messageEncoding="Mtom" 
    textEncoding="utf-8" transferMode="Buffered"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="8192" 
      maxArrayLength="16384" maxBytesPerRead="4096" 
      maxNameTableCharCount="16384" />
    <security mode="None">
      <transport clientCredentialType="None" 
        proxyCredentialType="None" realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>
</basicHttpBinding>

【问题讨论】:

    标签: wcf asmx


    【解决方案1】:

    从该消息看来,您的 WCF 服务正在正确返回 SOAP 消息,而您的客户端可能期望返回原始 POX(Plain Old XML)消息。

    这是什么客户?他们是否期望只对 URL 进行 REST 样式的调用并返回 XML 的有效负载??

    如果是这样,您需要更改您的 WCF 服务以使用 WebHttpBinding 而不是 basicHttpBinding(或为该客户端公开带有 webHttpBinding 的第二个端点)。

    【讨论】:

    • 希望有办法将此标记为答案,我将 web.config 修改为 weHttpBinding 并且它有效,但是我还必须使用这些页面上的此设置 stackoverflow.com/questions/1798069/…> 使用第二个最佳答案和 stackoverflow.com/questions/21204638/…>
    【解决方案2】:

    服务似乎返回了客户端不期望的 MTOM 编码响应。服务配置未指示使用 MTOM,因此可能未正确连接到服务。使用 Fiddler 或 WCF Logging 检查服务实际返回的内容。

    【讨论】:

    • 以上配置是使用svcutil工具添加代理时生成的。
    • 首先用 fiddler 验证这是服务器返回的内容。如果它返回 MTOM,则在此处发布完整的 web.config。
    猜你喜欢
    • 1970-01-01
    • 2012-04-17
    • 1970-01-01
    • 1970-01-01
    • 2012-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多