删除<;回报>;标签,用于使用PHP向Soap服务器提交数据

删除<;回报>;标签,用于使用PHP向Soap服务器提交数据,php,soap,Php,Soap,实际结果: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema

实际结果:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse>
            <return xsi:type="SOAP-ENC:Struct">
                <errorMsg xsi:type="xsd:string">Ok</errorMsg>
                <status xsi:type="xsd:string">0</status>
                <timeStamp xsi:type="xsd:string">2011-04-26T19:13:55.421875+05:00</timeStamp>
            </return>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

为了做您想要做的事情,您必须创建一个WSDL文档并将其传递给服务器和客户机。让我们开始创建一个名为
WSDL pruebas.WSDL
的WSDL文档,其中包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<definitions name="TransactionArguments"
             xmlns="http://schemas.xmlsoap.org/wsdl/"
             xmlns:xs="http://www.w3.org/2001/XMLSchema"
             xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
             xmlns:ns1="http://localhost/pruebas"
             targetNamespace="http://localhost/pruebas">
    <types>
        <xs:schema targetNamespace="http://localhost/pruebas">
            <xs:element name="PerformTransactionArgumentsResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="errorMsg" type="xs:string"/>
                        <xs:element name="status" type="xs:string"/>
                        <xs:element name="timeStamp" type="xs:string"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
    </types>

    <message name="PerformTransactionArgumentsRequest"/>
    <message name="PerformTransactionArgumentsResponse">
        <part name="return" element="ns1:PerformTransactionArgumentsResponse"/>
    </message>

    <portType name="PerformTransactionArgumentsPortType">
        <operation name="PerformTransactionArguments">
            <input message="PerformTransactionArgumentsRequest"/>
            <output message="PerformTransactionArgumentsResponse"/>
        </operation>
    </portType>

    <binding name="PerformTransactionArgumentsBinding" type="PerformTransactionArgumentsPortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="PerformTransactionArguments">
            <soap:operation soapAction=""/>
            <input/>
            <output>
                <soap:body use="encoded" namespace="http://localhost/pruebas" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>

    <service name="PerformTransactionArgumentsResponseService">
        <documentation>Returns an error message.</documentation>
        <port name="PerformTransactionArgumentsPort" binding="PerformTransactionArgumentsBinding">
            <soap:address location="http://localhost/pruebas/soap-server.php"/>
        </port>
    </service>
</definitions>
input
output
只需指向上述消息即可。接下来,我们定义portType的“详细信息”:

<binding name="PerformTransactionArgumentsBinding" type="PerformTransactionArgumentsPortType">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="PerformTransactionArguments">
        <soap:operation soapAction=""/>
        <input/>
        <output>
            <soap:body use="encoded" namespace="http://localhost/pruebas" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
        </output>
    </operation>
</binding>
这次我们提供了WSDL文档的URL,并修改了
$options
数组

为了查看所有这些操作,我们创建了一个SOAP客户端脚本(在本例中为
SOAP client.php
):

同样,我们指定WSDL文档的URL。运行客户端脚本将提供以下内容:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://localhost/pruebas" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse xsi:type="ns1:PerformTransactionArgumentsResponse">
            <errorMsg xsi:type="xsd:string">Ok</errorMsg>
            <status xsi:type="xsd:string">0</status>
            <timeStamp xsi:type="xsd:string">2011-04-26T19:13:55.421875+05:00</timeStamp>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我们将得到以下回应:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/pruebas" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse>
            <return xsi:type="ns1:PerformTransactionArgumentsResponse">
                <errorMsg xsi:type="xsd:string">Ok</errorMsg>
                <status xsi:type="xsd:string">0</status>
                <timeStamp xsi:type="xsd:string">2011-04-26T19:13:55.421875+05:00</timeStamp>
            </return>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

好啊
0
2011-04-26T19:13:55.421875+05:00
这是您当前得到的响应

编辑: 最后,如果我们更改soap:body行:

<soap:body use="encoded" namespace="http://localhost/pruebas" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>

为此:

<soap:body use="literal"/>

答复将是:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/pruebas">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse>
            <errorMsg>Ok</errorMsg>
            <status>0</status>
            <timeStamp>2011-04-26T19:13:55.421875+05:00</timeStamp>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

好啊
0
2011-04-26T19:13:55.421875+05:00

注意:为此,我假设脚本和WDSL位于
http://localhost/pruebas/

太好了,非常感谢,没想到会有这样的答案),但您能澄清一下我应该创建一个.wsdl文件:wsdl-pruebas.wsdl还是soap-pruebas.wsdl吗?首先,我认为无论如何命名该文件,但随后我发现错误SOAP-ENV:Server过程“PerformTransactionArguments”不存在。我试图自己解决它,但没有效果。原因可能是什么?我在Postman扩展中检查它,这有关系吗?您可以随意命名wsdl文件,只需确保在服务器和客户机中都正确引用它。我还没有用过邮递员,但应该可以用。另外,检查这个:非常感谢)我找到了解决方案,问题来自客户端,他们有自己的wsdl参数,最后它成功了。再次感谢:)
class PerformTransactionArgumentsResponse {
    public $errorMsg = "Ok";
    public $status = "0";
    public $timeStamp = "2011-04-26T19:13:55.421875+05:00";
}


class MyAPI {
    function PerformTransactionArguments() {
        return new PerformTransactionArgumentsResponse;
    }
}

$options = [
    'soap_version' => SOAP_1_1,
    'cache_wsdl' => WSDL_CACHE_NONE
];

$server = new SoapServer('http://localhost/pruebas/soap-pruebas.wsdl', $options);
$server->setClass('MyAPI');
$server->handle();
try {
    $options = [
        'soap_version' => SOAP_1_1,
        'trace'=>1
    ];

    $client = new SOAPClient('http://localhost/pruebas/soap-pruebas.wsdl', $options);

    $response = $client->PerformTransactionArguments();

    header('Content-type:text/xml');
    echo $client->__getLastResponse();
}
catch (SoapFault $e) {
    echo $e;
}
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://localhost/pruebas" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse xsi:type="ns1:PerformTransactionArgumentsResponse">
            <errorMsg xsi:type="xsd:string">Ok</errorMsg>
            <status xsi:type="xsd:string">0</status>
            <timeStamp xsi:type="xsd:string">2011-04-26T19:13:55.421875+05:00</timeStamp>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/pruebas" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse>
            <return xsi:type="ns1:PerformTransactionArgumentsResponse">
                <errorMsg xsi:type="xsd:string">Ok</errorMsg>
                <status xsi:type="xsd:string">0</status>
                <timeStamp xsi:type="xsd:string">2011-04-26T19:13:55.421875+05:00</timeStamp>
            </return>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
<soap:body use="encoded" namespace="http://localhost/pruebas" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
<soap:body use="literal"/>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/pruebas">
    <SOAP-ENV:Body>
        <ns1:PerformTransactionArgumentsResponse>
            <errorMsg>Ok</errorMsg>
            <status>0</status>
            <timeStamp>2011-04-26T19:13:55.421875+05:00</timeStamp>
        </ns1:PerformTransactionArgumentsResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>