dsfdsf21312 2010-04-12 09:57
浏览 41
已采纳

如何从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!

  • 写回答

1条回答 默认 最新

  • douzhiba6873 2010-04-19 00:58
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题