免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3034 | 回复: 2
打印 上一主题 下一主题

请教Soap 设setSoapHeaders的问题? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-27 14:55 |只看该作者 |倒序浏览
对方给的格式是
  1. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.ib.gh.com">
  2.    <soapenv:Header>
  3.     <AuthenticationToken>
  4.   <Username>gh</Username>
  5.   <Password>dsfsdf04d468f1772f95fgd1bf2b</Password>
  6.     </AuthenticationToken>
  7.    </soapenv:Header>
  8.    <soapenv:Body>
  9.    </soapenv:Body>
  10. </soapenv:Envelope>
复制代码
但我用过SoapHeader生成的xml是这样
  1. <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://ws.ib.gh.com">
  2. <SOAP-ENV:Header>
  3. <ns1:AuthenticationToken>
  4. <Username>gh</Username>
  5. <Password>dsfsdf04d468f1772f95fgd1bf2b</Password>
  6. </ns1:AuthenticationToken>
  7. </SOAP-ENV:Header>
  8. <SOAP-ENV:Body>
  9. </SOAP-ENV:Body>
  10. </SOAP-ENV:Envelope>
复制代码
怎么去掉AuthenticationToken前面的ns1呀?
  1.                
  2.                 $client = new SoapClient("http://www.yourcompany.com/Registration?wsdl");
  3.                 $headerbody = new AuthenticationToken();
  4.                 $headerbody->Username = 'gh';
  5.                 $headerbody->Password = 'dsfsdf04d468f1772f95fgd1bf2b';
  6.                 $header = new SoapHeader('http://ws.ib.sungold.com', 'AuthenticationToken', $headerbody);               
  7.                 //set the Headers of Soap Client.
  8.                 $client->__setSoapHeaders($header);
复制代码
有无试过可以过滤<ns1:AuthenticationToken>成<AuthenticationToken>;或者重构__setSoapHeaders()的呢,请教了。

论坛徽章:
0
2 [报告]
发表于 2012-07-27 17:06 |只看该作者
折磨了几天呀,终于搞定了
方法如下
  1.                
  2.               $strHeaderComponent_Session = "<AuthenticationToken><Username>gh</Username><Password>dsfsdf04d468f1772f95fgd1bf2b</Password></AuthenticationToken>";
  3.                 $objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
  4.                 $objHeader_Session_Outside = new SoapHeader('http://ws.ib.gh.com', 'AuthenticationToken', $objVar_Session_Inside);
  5.                 $client->__setSoapHeaders(array($objHeader_Session_Outside));
复制代码
就可以换成要求的格式了,不过还有不懂的是为什么php生成的参数前面都有ns1:的值。

论坛徽章:
0
3 [报告]
发表于 2012-07-30 11:18 |只看该作者
只用过 nusoap
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP