PHP SOAP Client不添加默认名称空间来请求参数

时间:2019-05-13 06:33:03

标签: php soap soap-client guzzle guzzlehttp

我真的在这个问题上挣扎。当PHP SOAP生成XML时,它不会添加默认名称空间,这会导致SOAP服务器出错。我不确定在这里做什么。

我测试了从PHP SOAP生成的XML,但它不起作用,但是当我手动添加默认xmlns时,它应能正常工作...

有人知道问题出在哪里吗?

以下是XSD文件的示例:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:common="http://services.test.com/xsd/common/1.0" xmlns:gus="http://services.test.com/GetBalance" xmlns:rq="http://services.test.com/GetBalance"  targetNamespace="http://services.test.com/GetBalance" attributeFormDefault="unqualified">
    <xs:import namespace="http://services.test.com/xsd/common/1.0" schemaLocation="CommonService.xsd"/>
    <xs:element name="GetBalanceRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="common:RequestHeader"/>
                <xs:element xmlns="http://services.test.com/GetBalance" name="RequestBody">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="ServiceNumber" type="common:ServiceNumber"/>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

这是有效的SOAP请求:

<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://services.test.com/xsd/common/1.0"
xmlns:ns2="http://services.test.com/GetBalance">
<SOAP-ENV:Body>
    <ns2:GetBalanceRequest>
        <ns1:RequestHeader>
            <ns1:TransactionId>027f5e30ee314f37a09e0949d0d0769f</ns1:TransactionId>
        </ns1:RequestHeader>
        <ns2:RequestBody>
            <ns2:ServiceNumber>11111</ns2:ServiceNumber>
        </ns2:RequestBody>
    </ns2:GetBalanceRequest>
</SOAP-ENV:Body>

这是PHP生成的请求:

 <SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns1="http://services.test.com/xsd/common/1.0"
xmlns:ns2="http://services.test.com/GetBalance">
<SOAP-ENV:Body>
    <ns2:GetBalanceRequest>
        <ns1:RequestHeader>
            <ns1:TransactionId>027f5e30ee314f37a09e0949d0d0769f</ns1:TransactionId>
        </ns1:RequestHeader>
        <RequestBody>
            <ServiceNumber>11111<ServiceNumber>
        </RequestBody>
    <ns2:/GetBalanceRequest>
</SOAP-ENV:Body>

如您所见,RequestBody标记没有默认名称空间(在此示例中为ns2),我不确定为什么...你们能告诉我如何解决此错误吗??

这也是我正在使用的PHP代码:

public function getRequest(): array
{

    return
        [
            $this->requestName => [
                'RequestHeader' => $this->getRequestHeader(),
                'RequestBody' => $this->getRequestBody(),
            ]
        ];
}

public function setClient()
{
    $factory = new Factory();
    $this->client = $factory->create(
        new Client([
            'cert' => $this->cert,
            'ssl_key' => $this->ssl_key
        ]),
        $this->wsdl,
        [
            'location' => $this->location,
            'uri' => 'http://services.test.com',
            'soap_version'=>SOAP_1_1,

        ]
    );

    return $this;
}

//Command that executes SOAP call based on https://github.com/meng-tian/async-soap-guzzle
this->getClient()->call($command, $request, $this->headers);

0 个答案:

没有答案
相关问题