2010-02-19 161 views
3

從客戶端使用我的WCF服務時,出現以下錯誤消息。問題是我能夠從Windows客戶端或控制檯應用程序輕鬆運行代碼。只是不從我的Web應用程序。WCF與非WCF客戶端

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> 

回答

1

從消息時,我們發現您的WCF服務正確返回一個SOAP消息,而你的客戶可能會期待生POX(普通老式XML)消息。

這是什麼樣的客戶端?他們是否希望對URL進行REST風格的調用並獲取XML的有效載荷?

如果是這樣,您需要更改WCF服務以使用WebHttpBinding而不是basicHttpBinding(或爲該客戶端公開webHttpBinding的第二個端點)。

+1

希望有一種方法可以將此標記爲答案,我將我的web.config修改爲weHttpBinding並且工作,但是我還必須使用這些頁面上的這些設置使用第二個最好的答案在這裏和 2014-04-04 15:46:10

1

看起來服務返回客戶端不期望的MTOM編碼響應。服務配置不表示使用MTOM,因此可能它沒有正確連接到服務。使用Fiddler或WCF日誌記錄檢查服務實際返回的內容。

+0

上面的配置是在使用svcutil工具添加代理時生成的。 – Kobojunkie 2010-02-20 17:13:56

+0

首先與提琴手驗證這是服務器返回的內容。如果它返回MTOM,則在此發佈完整的web.config。 – 2010-02-20 21:56:19