简体   繁体   English

在PHP中使用参数调用soap函数

[英]Calling soap function with parameters in PHP

I'm new to soap and I have this task where I need to send request and receive response. 我是肥皂新手,我有这个任务,我需要发送请求和接收响应。 However I get soap fault exception stating missing or invalid parameters. 但是,我得到肥皂故障异常,说明缺少或无效的参数。 I've been looking at the solution for hours but none have worked for me. 我一直在寻找解决方案几个小时,但没有一个对我有用。

I know my parameters aren't working but I am unaware of how to send them. 我知道我的参数不起作用,但我不知道如何发送它们。 I've wrapper them in an array as few solutions stated that but it hasn't worked for me. 我把它们包装在一个数组中,因为很少有解决方案说明了但它对我没用。

I would really appreciate if you could look at my situation and help me solve understand the situation. 如果你能看看我的情况并帮助我解决了解情况,我将非常感激。

If I connect with SOAP using SoapClient, and get functions and types I get the following: 如果我使用SoapClient连接SOAP,并获取函数和类型,我会得到以下内容:

SOAP FUNCTIONS: SOAP功能:

array (
        [0] => agentBalanceResult getAgentBalance(authorizationData $requesterAuthentication, agentIdentifier $targetAgent, string $productId,   string $requestTag)
)

<?php

SOAP TYPES: SOAP类型:

Array
(
[0] => struct authorizationData {
              aliasCategory aliasCategory;
              string aliasName;
              string aliasPassword;
              long mvnoId;
       }

[1] => struct agentIdentifier {
              long actorId;
              aliasCategory aliasCategory;
              string aliasName;
              long mvnoId;
       }
)

My Class that sends the request 发送请求的我的类

class SendRequest {

private $client;

public function __construct(){

    $this->client = new SoapClient(
                                    "myurl",
                                    [
                                        'location' => 'myurl'
                                    ]
                    );

}

public function sendRequestWithData(){

    //test parameters
    $testParameters = [

        "authorizationData" => [
            "aliasCategory" => "*****",
            "aliasName" => "*****",
            "aliasPassword" => "*****",
            "mvnoId" => "*****"
        ],

        "agentIdentifier" => [
            "actorId" => *****,
            "aliasName" => "*****",
            "aliasCategory" => "*****",
            "mvnoId" => "*****"
        ],

        "productId" => "*****",
        "requestTag" => "*****"

    ];

    $this->client->getAgentBalance($testParameters);

}

}

$send = new SendRequest;
$send->sendRequestWithData();

// throws Uncaught SoapFault exception: [env:Server] Missing or invalid SOAP request parameters in

My best advice is to use a WSDL to php generator. 我最好的建议是使用WSDL到php生成器。 It will generate classes that match the required parameters for constructing the request and you'll have the classes that match the response. 它将生成与构造请求所需参数匹配的类,并且您将拥有与响应匹配的类。 In addition you'll have the classes to send the request so yo won't wonder what parameters are required if you use a correct IDE with auto completion such as Eclipse PDT. 此外,您将拥有发送请求的类,因此如果您使用具有自动完成功能的正确IDE(例如Eclipse PDT),您将不会想知道需要哪些参数。 I can't propose you anything else that the PackageGenerator project to generate the classes that match the SoapClient WSDL structs and services. 我不能建议您使用PackageGenerator项目来生成与SoapClient WSDL结构和服务匹配的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM