dongshi3818 2011-11-23 10:57
浏览 73
已采纳

在PHP soap服务器和c#soap客户端之间设置编码

I have a PHP SOAP server (using nuSOAP with wsdl) that send the content of a html page. Of course, the HTML can be coded with differents encoding and here is when the problems appear. If I used a PHP SOAP client I can send the encoding like this:

$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')));

And if I put the correct encoding, has never failed so far. But when I use a C# client, how can I put the encoding in the web service petition? In C# the code is:

          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 is a Web reference of the wsdl, and when I see the "upload html" some characters aren't correct.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dqkv0603 2011-11-23 11:26
    关注

    nusoap internally uses the php function xml_parser_create, that only supports: ISO-8859-1, UTF-8 and US-ASCII. For this reason, this library don't works well with other encoding. Great PacHecoPe...

    UPDATE: The best option, in my case, is read the archive in its original encoding and transform it to 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: With encoding that not supported in UTF-8 like big5, don't work very well the above code. For this reason, it's better don't make the transform to UTF-8 and set the parameter with the content of html like base64Binary, in the wsdl.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 求华为P30PRO手机硬盘数据恢复
  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关
  • ¥15 TMC2209串口模式下读取不到寄存器的值串口助手蓝色字体是发过去的消息,绿色字体是收到的消息,第二行发送读取寄存器的指令但是没有读取到寄存器的值串口助手如下图:接线如下图,如何解决?
  • ¥15 高通安卓11提取完整线刷包软件,或者优博讯dt50顺丰刷机包
  • ¥20 C,有个译码器,换了信道就跑不出原来数据
  • ¥15 MIMIC数据库安装问题
  • ¥60 基于JTag协议开发Fpga下载器上位机,哪位大🐂有偿指导?
  • ¥20 全书网Java爬取数据
  • ¥15 怎么获取红包封面的原始链接,并且获取红包封面序列号
  • ¥100 微信小程序跑脚本授权的问题