如何从PHP SoapClient向ASP.NET SOAP服务器发送复杂类型?

问题描述:

Hello I'm having problems sending arrays, structs and arrays of structs from PHP to an ASP.NET SOAP server...

Anyone have a sollution for this? I've googled for days and any sollution worked for me. Perphaps I'm forgetting something...

There are examples of my code:

$client = new SoapClient($options);

$pCriteria = new stdClass();
$pCriteria->type=1;
$pCriteria->capacity=4;

//Test 1 (fail):
$resp = $client->GetRooms(array("pCriteria"=>$pCriteria));

//Test 2 (fail):
$resp = $client->GetRooms(array("pCriteria"=>new SoapVar($pCriteria, SOAP_ENC_OBJECT, "TCriteria", "http://www.w3.org/2001/XMLSchema")));

print_r($resp);

I don't know how to code functions that require an array of TCriteria (TCriteria[], TCriteria_Array type) either... i've tried sending the raw array, a SoapVar with SOAP_ENC_ARRAY encoding and TCriteria_Array type, ... but it does not work (the SOAP server becomes unavaiable and needs to be restarted).

I've tried creating classes for the complex types too, instead of stdClass, but not working.

I don't know where's the problem. The server admins cannot help me and I haven't found any sollution over internet. I'm a bit desperate hehe.

Can you help me please? Can you provide samples of code with the three cases (array of simple data, array of struct and struct) ? Thanks!

您好我在将数组,结构和结构数组从PHP发送到ASP.NET SOAP服务器时遇到问题。 .. p>

任何人都有解决方法吗? 我用Google搜索了几天,任何sollution都适合我。 Perphaps我忘了什么...... p>

我的代码有一些例子: p>

  $ client = new SoapClient($ options)  ; 
 
 $ pCriteria = new stdClass(); 
 $ pCriteria-> type = 1; 
 $ pCriteria-> capacity = 4; 
 
 //测试1(失败):
 $  resp = $ client-> GetRooms(array(“pCriteria”=> $ pCriteria)); 
 
 //测试2(失败):
 $ resp = $ client-> GetRooms(array(“pCriteria”  “=> new SoapVar($ pCriteria,SOAP_ENC_OBJECT,”TCriteria“,”http://www.w3.org/2001/XMLSchema“))); 
 
print_r($ resp); 
  code>   pre> 
 
 

我不知道如何编写需要一系列TCriteria(TCriteria [],TCriteria_Array类型)的函数...我已经尝试发送原始数组,一个SoapVar与 SOAP_ENC_ARRAY编码和TCriteria_Array类型,但它不起作用(SOAP服务器变得不可用,需要重新启动)。 p>

我也尝试过为复杂类型创建类, 而不是stdClass,但没有工作。 p>

我不知道问题出在哪里。 服务器管理员无法帮助我,我没有在互联网上找到任何解决方案。 我有点绝望嘿嘿。 p>

你能帮帮我吗? 你能提供三种情况的代码样本(简单数据数组,结构和结构数组)吗? 谢谢! p> div>

I had a similar situation with a PHP Soap Client communicating with a .NET Soap Server using WSDL 2.0. Here's one thing I discovered: When passing the information to the server, you must explicitly define the variable as a SoapVar object. So in your example above, change it to:

$pCriteria->type = new SoapVar(1, XSD_INT, 'xsd:int');

Passing an array is similar, essentialy you pass an array of SoapVars:

$pCriteria->type = array(new SoapVar(1, XSD_INT, 'xsd:int'), new SoapVar(2, XSD_INT, 'xsd:int', new SoapVar(3, XSD_INT, 'xsd:int'));`enter code here`

Also, you can use several built-in functions of the SoapClient to get some additional feedback on possible errors.

$client->__getLastRequest() //To display the XML that you sent to the server
$client->__getLastResponse() //to display the XML that is sent in response to your request

If you can get a copy of the expected WSDL format you can use the response from the above commands to determine what is going wrong. Usually you can access this from the URL that you pass to the SoapClient. So, for example, if the WSDL services URL is http://example.com/webservices/wvrgroupservice.asmx?WSDL, enter http://example.com/webservices/wvrgroupservice.asmx to view the functions and expected XML from that server.