<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="GAAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:reverseResponse><return xsi:type="xsd:string"></return></ns1:reverseResponse></SOAP-ENV:Body></SOAP-ENV:Envelo
这是我用PHP5.2 SoapClient返回的LastResponse结果, 我抓包看HTTP返回的数据是完整的,但是getLastResponse却是少了最后三个字节pe>, 所以就报SoapFault异常. 不管是服务端还是客户端的网卡抓包看, HTTP返回数据都是完整的,没有缺那三个字节.下面贴上代码
server的
<?   
include_once('soapfunc.php');   
$soap = new SoapServer(null,array('uri'=>"GAAuth"));   
$soap->addFunction('reverse');   
$soap->addFunction('add2numbers');   
$soap->addFunction('gettime');   
//$soap->addFunction(SOAP_FUNCTIONS_ALL);   
$soap->handle();   
?>  客户端的
<?   
try 
{   
        $client = new SoapClient
         (null, 
         array
         (
         'location' =>"http://172.16.200.8:82/GAAuth/soapserver.php",
         'uri'  => "GAAuth",
         //'style'    => SOAP_RPC, 
         //'use'      => SOAP_ENCODED,
         "trace"=>1, 
         "exceptions"=>0
         )
         );   
        
        
        $str = "This string will be reversed";   
        $reversed = $client->reverse($str); 
        //var_dump($client->__getLastResponseHeaders());
//var_dump($client->__getLastResponse());
$strDump=$client->__getLastResponse();
echo $strDump;
echo "\n\n";
$strDump2="aaaa " . $client->__getLastResponse() . " bbbb";
echo $strDump2;

echo "The system time is: ",$client->gettime();

        echo "If you reverse '",$str,"', you get '",$reversed,"'";   
        $n1=20;   
        $n2=33;   
        $sum = $client->add2numbers($n1,$n2);   
        echo "If you try ",$n1,"+",$n2,", you will get ",$sum,"";   
           

catch (SoapFault $fault)
{   
        echo "Fault! code:",$fault->faultcode,", string: ",$fault->faultstring;   
}  
?> 都是最简单的测试webservice的代码,咋这么怪呢

解决方案 »

  1.   

    奇怪,我本地测试你的例子没错呀,版本为5.1.2.
    我只在服务端加了个reverse方法进行测试.
    结果desrever eb lliw gnirts sihT aaaa <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="GAAuth" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:reverseResponse><return xsi:type="xsd:string">desrever eb lliw gnirts sihT</return></ns1:reverseResponse></SOAP-ENV:Body></SOAP-ENV:Envelope> bbbb
      

  2.   

    郁闷啊, 怎么就缺三个字节呢.  是不是 apache server或php做点什么配置呢. 换了几台机器都是这个问题
      

  3.   

    你返回的http header是什么样的呢?贴出来看看
      

  4.   

    我检查过http头了, soap返回包的长度是501字节, http头里面的length也是501. 但是很奇怪的,head的\r\n\r\n后面, 在<?xml 前面, 多了两个空格和一个回车换行. 也就是多了一个空行,正好四个字节.
    多了四个字节, 但header里面的长度并没有+4, 导致最后丢了关键的pe/>我换个apache试试看
      

  5.   

    嗯. 仔细DEBUG一下吧.. 我估计应该是编码的问题.或者是BOM头的三个字节的问题.
      

  6.   

    找到问题的原因了: 那个.php文件有问题, 里面有不可见字符. 网页上拷贝的代码, 真够恶心的. 后来自己重写了一遍php就好了.唉, 浪费了两天时间. 
    至于为什么三个不可见字符能让apache返回数据混乱, 就不得而知了.  给大家散分, 参与者皆有份
      

  7.   

    501字节是php的soapserver生成的返回soap xml数据, 总共501个字节, 交给apache也是501个, 所以apache在生成返回http 头的时候, 就放了lenght:501. 不知实际http content部分又多了4个字节. 这多的四个字节, 原因跟.php文件中多的不可见字符有关系. 让人昏倒的问题