2011-11-23 145 views
0

我有一個發送html頁面內容的PHP SOAP服務器(使用帶有wsdl的nuSOAP)。當然,HTML可以用不同的編碼進行編碼,問題出現在這裏。如果我使用了PHP SOAP客戶端,我可以送的編碼是這樣的:在PHP肥皂服務器和c#soap客戶端之間設置編碼

$clienteSOAP = new SoapClient ("http://test.mine.com/wsdl/filemanager?wsdl", 
           array ('encoding' => 'ISO-8859-15')); 
$clienteSOAP->__soapCall ("Test.uploadHTML", 
      array (file_get_contents ('/home/КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html'))); 

如果我把正確的編碼,從來到目前爲止還沒有。但是當我使用C#客戶端時,如何將編碼放入Web服務請求中?在C#代碼:

  System.IO.StreamReader html = new System.IO.StreamReader (
        "C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html" 
        ,System.Text.Encoding.GetEncoding("iso-8859-15")); 
      string contenido = html.ReadToEnd(); 
      html.Close(); 

      Test.FileManager upload = new Test.FileManager(); 
      string resultado = upload.TestUploadHTML (contenido); 

Test.FileManager是WSDL的Web引用,當我看到「上傳HTML」,一些字符是不正確的。

在此先感謝。

回答

0

的NuSOAP內部使用PHP函數xml_parser_create,僅支持:ISO-8859-1,UTF-8和US-ASCII。出於這個原因,這個庫不適合其他編碼。大PacHecoPe ...

UPDATE:最好的選擇,在我的情況下,讀取檔案的原始編碼,並把它轉換爲UTF-8:

System.IO.StreamReader html = new System.IO.StreamReader (
       "C:\\Documents and Settings\\КОЛЛЕКЦИЯ_РОДНИК_ПРЕМИУМ.html" 
       ,System.Text.Encoding.GetEncoding("iso-8859-15")); 

string contenido = html.ReadToEnd(); 
html.Close(); 

System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding(); 
byte[] bytes = System.Text.Encoding.UTF8.GetBytes (contenido); 
string contenidoUTF8 = encoder.GetString(bytes); 

upload.RequestEncoding = System.Text.Encoding.GetEncoding("UTF-8"); 

Test.FileManager upload = new Test.FileManager(); 
string resultado = upload.TestUploadHTML (contenidoUTF8); 

UPDATE2:用編碼UTF-8不支持像big5,不能很好地運行上面的代碼。出於這個原因,最好不要在UTF-8上進行轉換,並在wsdl中設置帶有html的內容的參數,如base64Binary