首页 > 解决方案 > SOAP 错误 - PHP 中的 VersionMismatch 但 SOAP UI 正常

问题描述

尝试在php中调用 Web 服务时收到错误消息:SoapFault 异常:[ VersionMismatch ] 错误版本。

但是当我在SOAP UI中执行 $client->__getLastRequest() 的结果时,该函数在服务器端运行良好。

这是我的 wsdl(我用 localhost 替换了我的服务器名称):

<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions 
    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:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    xmlns:tns="urn:PDF_API" 
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns="http://schemas.xmlsoap.org/wsdl/" 
    targetNamespace="urn:PDF_API"
>
<types>
    <xsd:schema targetNamespace="urn:PDF_API"></xsd:schema>
</types>
<message name="html_to_pdf_request">
  <part name="html" type="xsd:string" />
</message>
<message name="html_to_pdf_response">
  <part name="pdf" type="xsd:string" />
</message>
<portType name="PDF_API_PortType">
  <operation name="html_to_pdf">
    <documentation>Convertit le HTML en format PDF</documentation>
    <input message="tns:html_to_pdf_request"/>
    <output message="tns:html_to_pdf_response"/>
  </operation>
</portType>
<binding name="PDF_API_Binding" type="tns:PDF_API_PortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="html_to_pdf">
    <soap:operation soapAction="urn:html_to_pdf2/html_to_pdf" style="rpc"/>
    <input><soap:body use="encoded" namespace="urn:html_to_pdf2" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
    <output><soap:body use="encoded" namespace="urn:html_to_pdf2" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
  </operation>
</binding>
<service name="PDF_API">
  <port name="PDF_API_Port" binding="tns:PDF_API_Binding">
    <soap:address location="http://localhost/PDF_API/PDF_API.php"/>
  </port>
</service>
</definitions>  

我这样调用网络服务

try{
            $client = new SoapClient(
                                    pdfApiWSDL,
                                    array(
                                        'soap_version'   => SOAP_1_1,
                                        'cache_wsdl' => WSDL_CACHE_NONE,
                                        'trace'=>1)
                                    );

            $client->__setLocation(pdfApiWSDL);
                        $res = $client->html_to_pdf('test');


        } catch (Exception $e) {

        }

这是我的信封:

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:html_to_pdf2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://www.w3.org/2003/05/soap-encoding">
    <env:Body>
        <ns1:html_to_pdf env:encodingStyle="http://www.w3.org/2003/05/soap-encoding">
            <html xsi:type="xsd:string">test

            </html>
        </ns1:html_to_pdf>
    </env:Body>
</env:Envelope>

我已经检查过这个 SOAP 错误是否意味着我认为的意思?但没有任何帮助

编辑

问题已解决,错误信息令人困惑!我刚刚将链接更改为 wsdl 从

http://myserver/PDF_API/PDF_API.php.wsdl

http://myserver/PDF_API/PDF_API.php?wsdl

……然后魔法发生了。

标签: phpsoapwsdlsoapui

解决方案


推荐阅读