热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何将nuSOAP用于具有多个名称空间的消息-HowtousenuSOAPformessageswithmultiplenamespaces

ImtryingtoaccessaWebServiceusingnuSOAP(becauseImboundtoPHP4here)thatusesmorethan

I'm trying to access a WebService using nuSOAP (because I'm bound to PHP4 here) that uses more than 1 namespace in a message. Is that possible?

我正在尝试使用nuSOAP访问WebService(因为我在这里绑定了PHP4),它在消息中使用了多个命名空间。那可能吗?

An example request message would look like this:

示例请求消息如下所示:


  
  
    
      
        ..
        ..
      
      ..
    
  

I tried to following:

我试着跟随:

$client = new nusoap_client("my.wsdl", true);
$params = array(
  'Person' => array(
    'FirstName'  => 'Thomas',
    ..
   ),
   'Attribute' => 'foo'
 );

 $result = $client->call('myOperation', $params, '', 'soapAction');

in the hope that nuSOAP would try to match these names to the correct namespaces and nodes. Then I tried to use soapval() to generate the elements and their namespace - but if I call an operation, nuSOAP creates the following request:

希望nuSOAP尝试将这些名称与正确的名称空间和节点相匹配。然后我尝试使用soapval()生成元素及其命名空间 - 但是如果我调用一个操作,nuSOAP会创建以下请求:


  
    
  

So something goes wrong during the "matching" phase.

因此在“匹配”阶段出现问题。

4 个解决方案

#1


After trying around with the matching, I found two possible solutions:

在尝试匹配之后,我发现了两种可能的解决方案:

1) Don't use the WSDL to create the nusoap_client and soapval() to create the message This has the disadvantage that the message contains a lot of overhead (the namespace is defined in each element). Not so fine.

1)不要使用WSDL创建nusoap_client和soapval()来创建消息。这样做的缺点是消息包含大量开销(命名空间在每个元素中定义)。不太好。

2) Instead of relying on the matching of parameters, construct your reply in xml and put all the definition for prefixes in the first element - e.g.

2)不是依赖于参数的匹配,而是在xml中构造你的回复并将前缀的所有定义放在第一个元素中 - 例如

$params = "
      
        ..
        ..
      
      ..
    ";

Still not a very nice solution, but it works :-)

仍然不是一个非常好的解决方案,但它的工作原理:-)

#2


Building on Irwin's post, I created the xml manually and had nusoap do the rest. My webhost does not have the php soap extension, so I had to go with nusoap, and the web service I'm trying to consume required the namespaces on each tag (e.g. on username and password in my example here).

在Irwin的帖子的基础上,我手动创建了xml,剩下的就是nusoap。我的webhost没有php soap扩展,因此我不得不使用nusoap,而我正在尝试使用的Web服务需要每个标记上的命名空间(例如,在我的示例中使用用户名和密码)。

require_once('lib/nusoap.php');

$client = new nusoap_client('https://service.somesite.com/ClientService.asmx');
$client->soap_defencoding = 'utf-8';
$client->useHTTPPersistentConnection(); // Uses http 1.1 instead of 1.0
$soapaction = "https://service.somesite.com/GetFoods";

$request_xml = '

  
    
      banjer
      theleftorium
    
  

';

$respOnse= $client->send($request_xml, $soapaction, ''); 

echo '

Request

' . htmlspecialchars($client->request, ENT_QUOTES) . '
'; echo '

Response

' . htmlspecialchars($client->response, ENT_QUOTES) . '
'; echo '

Debug

' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '
';

Then I had an error that said:

然后我有一个错误说:

Notice: Undefined property: nusoap_client::$operation in ./lib/nusoap.php  on line 7674

So I went the lazy route and went into nusoap.php and added this code before line 7674 to make it happy:

所以我走了懒惰的路线进入nusoap.php并在第7674行之前添加了这段代码以使它开心:

    if(empty($this->operation)) {
        $this->operation = "";
    }

#3


Another bypass this issue would be a modification to nusoap_client::call() function. Next to the this line (7359 in version 1.123) in nusoap.php:

另一个绕过这个问题的是对nusoap_client :: call()函数的修改。在nusoap.php的这一行(版本1.123中的7359)旁边:

$nsPrefix = $this->wsdl->getPrefixFromNamespace($namespace);

$ nsPrefix = $ this-> wsdl-> getPrefixFromNamespace($ namespace);

I added this one:

我添加了这个:

$nsPrefix = $this->wsdl->getPrefixFromNamespace("other_ns_name");

And it worked! Since I only needed this library for one project, it was OK for me to hardcode this hack. Otherwise, I would dig more and modify the function to accept array instead of string for a namespace parameter.

它奏效了!由于我只为一个项目需要这个库,所以我可以硬编码这个hack。否则,我会挖掘更多并修改函数以接受数组而不是字符串作为命名空间参数。

#4


Yeah, i've been having this same problem (found your q via google!) and i've come across this: http://www.heidisoft.com/blog/using-nusoap-consume-net-web-service-10-min Here, the dev creates the xml body of the message in coe and then uses nusoap to submit.

是的,我一直有同样的问题(通过谷歌找到你的q!)我遇到过这个问题:http://www.heidisoft.com/blog/using-nusoap-consume-net-web-service- 10分钟在这里,dev在coe中创建消息的xml主体,然后使用nusoap提交。


推荐阅读
author-avatar
史军2927
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有