在发送请求之前/不发送请求之前,检查由PHP SoapClient调用创建的XML [英] Inspect XML created by PHP SoapClient call before/without sending the request

查看:79
本文介绍了在发送请求之前/不发送请求之前,检查由PHP SoapClient调用创建的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题: 在实际发送请求之前,有没有办法查看将通过PHP SoapClient函数调用创建的XML?

The question: Is there a way to view the XML that would be created with a PHP SoapClient function call BEFORE you actually send the request?

背景:

我是WSDL通信的新手,我有一个客户希望我用PHP开发,这是一种与用ASP.NET编写的WSDL服务进行通信的方式.我已经走得很远了,但是在传递复杂类型时遇到了一个问题.到目前为止,我已经尝试了几种不同的方法.

I am new to WSDL communication, and I have a client who wants me to develop in PHP, a way to communicate with a WSDL service written in ASP.NET. I have gotten pretty far, but am running into an issue when it comes to passing a complex type. I have tried a couple of different things so far.

1)设置单个数组,例如$params->Person->name $params->Person->address

1) Setting up a single array such as $params->Person->name $params->Person->address

2)设置单个阵列$Person = array('name'=>"joe",'address' = "123");

然后作为参数"Person"传递到调用中=> $ Person; 和其他一些.但是每次我得到错误

then passing into the call as a param "Person" => $Person; and a few others. But every time I get the error

SoapException:服务器无法执行 流程请求---> System.Exception: 必须为人.服务名称.

SoapException: Server was unable to process request ---> System.Exception: Person is Required. at service name.

为了进一步进行故障排除,我想查看正在发送的XML文档,以查看它是否正在按照我期望的方式创建复杂类型. 我正在使用$client = new SoapClient('wsdldoc.asmx?WSDL');创建一个服务,然后使用$client->CreateUser($params);调用它,然后尝试使用函数$client->__getLastRequest();看到它,但它从未进入__getLastRequest,因为调用CreateUser($ params)时会遇到致命错误.

In order to further the troubleshooting, I would like to see the XML document that is being sent to see if it is creating a complex type in the way I am expecting it to. I am creating the service using $client = new SoapClient('wsdldoc.asmx?WSDL'); calling it with $client->CreateUser($params); and then trying to see it using the function $client->__getLastRequest(); but it never makes it to the __getLastRequest because it hits a fatal error when calling CreateUser($params).

问题再次出现: 有什么方法可以查看由CreateUser($ params)调用创建的XML,而无需实际发送它并导致致命错误

The question again: Is there any way to view the XML created by the CreateUser($params) call WITHOUT actually sending it and causing a fatal error

推荐答案

前言:为了使用

Upfront remark: In order to use the __getLastRequest() method successfully, you have to set the 'trace' option to true on client construction:

$client = new SoapClient('wsdldoc.asmx?WSDL', array('trace' => TRUE));

这样,您的请求仍会发送(因此仍然失败),但是您可以通过调用$client->__getLastRequest()之后检查发送的xml .

This way, your request will still be sent (and therefore still fail), but you can inspect the sent xml afterwards by calling $client->__getLastRequest().

主要答案:

要在发送请求之前/不发送之前访问生成的XML,您需要对SoapClient进行子类化以覆盖

To get access to the generated XML before/without sending the request, you'd need to subclass the SoapClient in order to override the __doRequest() method:

class SoapClientDebug extends SoapClient
{
  public function __doRequest($request, $location, $action, $version, $one_way = 0) {
      // Add code to inspect/dissect/debug/adjust the XML given in $request here

      // Uncomment the following line, if you actually want to do the request
      // return parent::__doRequest($request, $location, $action, $version, $one_way);
  }
}

然后在调试问题时将使用此扩展类而不是原始的SoapClient.

You'd then use this extended class instead of the original SoapClient while debugging your problem.

这篇关于在发送请求之前/不发送请求之前,检查由PHP SoapClient调用创建的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆