gh520 发表于 2012-07-27 14:55

请教Soap 设setSoapHeaders的问题?

对方给的格式是<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ib.gh.com">
   <soapenv:Header>
    <AuthenticationToken>
<Username>gh</Username>
<Password>dsfsdf04d468f1772f95fgd1bf2b</Password>
    </AuthenticationToken>
   </soapenv:Header>
   <soapenv:Body>
   </soapenv:Body>
</soapenv:Envelope>但我用过SoapHeader生成的xml是这样<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.ib.gh.com">
<SOAP-ENV:Header>
<ns1:AuthenticationToken>
<Username>gh</Username>
<Password>dsfsdf04d468f1772f95fgd1bf2b</Password>
</ns1:AuthenticationToken>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>怎么去掉AuthenticationToken前面的ns1呀?               
                $client = new SoapClient("http://www.yourcompany.com/Registration?wsdl");
                $headerbody = new AuthenticationToken();
                $headerbody->Username = 'gh';
                $headerbody->Password = 'dsfsdf04d468f1772f95fgd1bf2b';
                $header = new SoapHeader('http://ws.ib.sungold.com', 'AuthenticationToken', $headerbody);               
                //set the Headers of Soap Client.
                $client->__setSoapHeaders($header);
有无试过可以过滤<ns1:AuthenticationToken>成<AuthenticationToken>;或者重构__setSoapHeaders()的呢,请教了。

gh520 发表于 2012-07-27 17:06

折磨了几天呀,终于搞定了
方法如下               
            $strHeaderComponent_Session = "<AuthenticationToken><Username>gh</Username><Password>dsfsdf04d468f1772f95fgd1bf2b</Password></AuthenticationToken>";
                $objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
                $objHeader_Session_Outside = new SoapHeader('http://ws.ib.gh.com', 'AuthenticationToken', $objVar_Session_Inside);
                $client->__setSoapHeaders(array($objHeader_Session_Outside));
就可以换成要求的格式了,不过还有不懂的是为什么php生成的参数前面都有ns1:的值。

maochanglu 发表于 2012-07-30 11:18

只用过 nusoap
页: [1]
查看完整版本: 请教Soap 设setSoapHeaders的问题?