2011-11-23 139 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