2011-06-21 14 views
2

我在Visual Studio 2008中完成了一個項目,並在Monodevelop 2.4.2和mono 2.10.2的Linux上重建了它。單聲道:Web服務在XML中預先填寫UTF-8 BOM

由單版本產生的輸出SOAP被包括UTF-8 BOM(EF BB BF)不能由該服務器來處理報頭,生成下面的異常:

"Couldn't create SOAP message due to exception: XML reader error: com.sun.xml.stream.XMLStreamException2: ParseError at [row,col]:[1,1] 
Message: Content is not allowed in prolog." 

我怎樣才能指示單聲道自動生成的webservice客戶端不包含此BOM?

Wireshark的嗅探:

000000B5 ef bb bf 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e ...<?xml version 
000000C5 3d 22 31 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d ="1.0" e ncoding= 
000000D5 22 75 74 66 2d 38 22 3f 3e 3c 73 3a 45 6e 76 65 "utf-8"? ><s:Enve 

回答

0

如果使用basicHttpBinding的客戶端創建,你應該設置編碼無BOM

ClientBaseImp client = new ClientBaseImp(); 
((BasicHttpBinding)client.Endpoint.Binding).TextEncoding 
     = new UTF8Encoding(false); 

最後一行new UTF8Encoding(false)刪除BOM。

+0

您應該添加一點解釋 –

+0

您應該使用'BasicHttpBinding'而不是'as'作爲運算符。如果出現錯誤,你最終會得到'ObjectNullReference'異常,而顯式轉換會給你一個線索,你不能轉換成'BasicHttpBinding'。所以,使用'((BasicHttpBinding)client.Endpoint.Binding).TextEncoding'。 – Artemix