繼續WCF路由測試樣例,錯誤提示:
響應消息的內容類型 multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:da79eb0e-af0d-4754-8e19-474b1261a624+id=2";start-info="text/xml" 與綁定(text/xml; charset=utf-8)的內容類型不匹配。如果使用自定義編碼器,請確保正確實現 IsContentTypeSupported 方法。響應的前 1024 個字節為:“
--uuid:da79eb0e-af0d-4754-8e19-474b1261a624+id=2
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
后來發現還是路由時的綁定配置問題,我的路由樣例是wsHttpBinding綁定去路由兩個BasicHttpBinding綁定,而BasicHttpBinding綁定中實現的是文件的上傳和下載。由於在BasicHttpBinding中使用了messageEncoding="Mtom",而在路由的時候沒有增加所以報錯……
后來在路由中,增加了相應的配置,即解決了問題。
BasicHttpBinding tc = new BasicHttpBinding(); tc.TransferMode = TransferMode.Streamed; tc.MessageEncoding = WSMessageEncoding.Mtom;