呼叫WebService時出現「The formatter threw an exception while trying to deserialize the message…」錯誤

 

The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter WS名稱:方法名稱Response. The InnerException message was ‘There was an error deserializing the object of type 專案名稱.WS名稱.方法名稱ResponseBody. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader. Line 1, position 13880.’. Please see InnerException for more details.

 

下面是原本 Web.config 預設的 WebService 的內容

<system.servicemodel>
    <bindings>
        <basichttpbinding>
            <binding name="WebServiceSoap">
        </binding></basichttpbinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.com.tw/WebService.asmx" binding="basicHttpBinding" bindingconfiguration="WebServiceSoap" contract="WebService.WebServiceSoap" name="WebServiceSoap">
    </endpoint></client>
</system.servicemodel>

 

修改成以下內容後就會正常

<system.servicemodel>
    <bindings>
        <basichttpbinding>
            <binding maxreceivedmessagesize="2147483647" name="WebServiceSoap">
                <readerquotas maxarraylength="2147483647" maxbytesperread="2147483647" maxdepth="2147483647" maxnametablecharcount="2147483647" maxstringcontentlength="2147483647">
            </readerquotas></binding>
        </basichttpbinding>
    </bindings>
    <client>
        <endpoint address="http://xxx.com.tw/WebService.asmx" binding="basicHttpBinding" bindingconfiguration="WebServiceSoap" contract="WebService.WebServiceSoap" name="WebServiceSoap">
    </endpoint></client>
</system.servicemodel>

 

 

 

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *