简体   繁体   English

使用SoapClient类的PHP SOAP调用问题

[英]PHP SOAP call issue using the SoapClient class

I am badly stuck in creating a client to consume this WSDL. 我在创建客户端以使用此WSDL方面陷入了困境。 (I am a novice when it comes to consuming webservices in PHP.) (For confidentiality reasons, I had to create a replica XML. I hope you understand.) (在PHP中使用Web服务时,我是一个新手。)(出于保密原因,我必须创建一个副本XML。希望您能理解。)

http://brique.in/wsdl.xml http://brique.in/wsdl.xml

I use the following code to print out the functions and the types: 我使用以下代码打印出函数和类型:

$client = new SoapClient("http://brique.in/wsdl.xml");
var_dump($client->__getFunctions()); 
var_dump($client->__getTypes()); 

I am trying to write php code to call the method inwardProcess . 我正在尝试编写php代码来调用方法inwardProcess It accepts as an input, an XML file. 它接受XML文件作为输入。 I tried the following: 我尝试了以下方法:

$xmlInput = htmlentities('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
$result = $client->__soapCall("inwardProcess", array($xmlInput));

It didn't work. 没用 After looking at the WSDL specifications, I also tried, 在查看了WSDL规范之后,我还尝试了,

$xmlInput = htmlentities('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
class inwardProcess {
    function inwardProcess($xmlInput) 
    {
        $this->xmlInput = $xmlInput;
    }
}
$inwardProcess = new inwardProcess($xmlInput);
$webservice = new SoapClient($url, $soap_options);
echo "Attempting Inward<br/>";
try {
    var_dump($webservice->__getTypes()); 
    //I also tried passing just $inwardProcess Object in place of array($inwardProcess)
    $result = $webservice->__soapCall("inwardProcess", array($inwardProcess));
    var_dump($result); 
} catch (SOAPFault $f) {
    echo "SOAPFault".$f;
}

I keep getting the error 我不断收到错误

Server was unable to process request. ---> Object reference not set to an instance of an object

Somehow I am not able to work it out. 不知何故我无法解决。 Any help would be highly appreciated since I am on a deadline. 自从我在最后期限之前,任何帮助将不胜感激。

When structures are as complex as: 当结构如此复杂时:

<s:element name="inwardProcess">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="xmlInput">
                <s:complexType mixed="true">
                    <s:sequence>
                        <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>

and response like 和像

<s:element name="inwardProcessResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="inwardProcessResult">
                <s:complexType mixed="true">
                    <s:sequence>
                        <s:any/>
                    </s:sequence>
                </s:complexType>
            </s:element>
        </s:sequence>
    </s:complexType>
</s:element>

You have to create a class for each structure. 您必须为每个结构创建一个类。 In this case, it would be: 在这种情况下,它将是:

class xmlInput
{
    public $any = null;
    public function __construct($any)
    {
        $this->any = $any;
    }
}

class inwardProcess
{
    public $xmlInput = null;
    public function __construct($xmlInput)
    {
        $this->xmlInput = $xmlInput;
    }
}
class inwardProcessResponse
{
    public $inwardProcessResult = null;
    public function __construct($inwardProcessResult)
    {
        $this->inwardProcessResult = $inwardProcessResult;
    }
}

and finally call ... 最后打电话给...

$xmlInput = new xmlInput('<XML><Refno>H9999999</Refno><Type>getDetails</Type><UserID>BO</UserID></XML>');
$inwardProcess = new inwardProcess($xmlInput);
$soap_options = array(
    'trace'       => 1,     // traces let us look at the actual SOAP messages later
    'exceptions'  => 1 );
$url = "<WSDL URL>";
$client = new SoapClient($url, $soap_options);
try {
    $result = $client->__soapCall("inwardProcess", array($inwardProcess));
    echo htmlentities($result->inwardProcessResult->any);
} catch (SOAPFault $f) {
    echo "-1";
}

Worked! 工作了!

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

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