PHP使用xml文件而不是wsdl的SOAP请求

时间:2017-07-24 11:36:48

标签: php xml web-services soap wsdl

我正在尝试使用网络服务(Swiss Post Track托运)更新Prestashop订单状态,以便在交付时交付。

我为请求提供的文件看起来像这样(.xml)

<?xml version="1.0" encoding="UTF-8"?>

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap11="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp200409="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsp200607="http://www.w3.org/2006/07/ws-policy" xmlns:ns0="http://www.post.ch/npp/trackandtracews/v02/masterdata/definitions" targetNamespace="http://www.post.ch/npp/trackandtracews/v02/masterdata/definitions">
<wsdl:types xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:schema>
<xsd:import schemaLocation="MasterData.ws.xsd1.xsd" namespace="http://www.post.ch/npp/masterdata/v02"/></xsd:schema></wsdl:types>
<wsdl:message name="DetailRequest">
<wsdl:part name="DetailRequest" element="xsns:DetailReq" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:message name="DetailResponse">
<wsdl:part name="DetailResponse" element="xsns:DetailRes" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:message name="EventsRequest">
<wsdl:part name="EventsRequest" element="xsns:EventsReq" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:message name="EventsResponse">
<wsdl:part name="EventsResponse" element="xsns:EventsRes" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:message name="StatusesRequest">
<wsdl:part name="StatusesRequest" element="xsns:StatusReq" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:message name="StatusesResponse">
<wsdl:part name="StatusesResponse" element="xsns:StatusRes" xmlns:xsns="http://www.post.ch/npp/masterdata/v02"/></wsdl:message>
<wsdl:portType name="MasterDataResource">
<wsdl:operation name="GetAllDetails">
<wsdl:input name="DetailRequest" message="ns0:DetailRequest"/>
<wsdl:output name="DetailResponse" message="ns0:DetailResponse"/></wsdl:operation>
<wsdl:operation name="GetAllEvents">
<wsdl:input name="EventsRequest" message="ns0:EventsRequest"/>
<wsdl:output name="EventsResponse" message="ns0:EventsResponse"/></wsdl:operation>
<wsdl:operation name="GetAllStatuses">
<wsdl:input name="StatusesRequest" message="ns0:StatusesRequest"/>
<wsdl:output name="StatusesResponse" message="ns0:StatusesResponse"/></wsdl:operation></wsdl:portType>
<wsdl:binding name="MasterDataBinding" type="ns0:MasterDataResource">
<soap11:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetAllDetails">
<soap11:operation soapAction="http://www.post.ch/npp/masterdataws/v02/GetAllDetails" style="document"/>
<wsdl:input name="DetailRequest">
<soap11:body use="literal"/></wsdl:input>
<wsdl:output name="DetailResponse">
<soap11:body use="literal"/></wsdl:output></wsdl:operation>
<wsdl:operation name="GetAllEvents">
<soap11:operation soapAction="http://www.post.ch/npp/masterdataws/v02/GetAllEvents" style="document"/>
<wsdl:input name="EventsRequest">
<soap11:body use="literal"/></wsdl:input>
<wsdl:output name="EventsResponse">
<soap11:body use="literal"/></wsdl:output></wsdl:operation>
<wsdl:operation name="GetAllStatuses">
<soap11:operation soapAction="http://www.post.ch/npp/masterdataws/v02/GetAllStatuses" style="document"/>
<wsdl:input name="StatusesRequest">
<soap11:body use="literal"/></wsdl:input>
<wsdl:output name="StatusesResponse">
<soap11:body use="literal"/></wsdl:output></wsdl:operation></wsdl:binding>
<wsdl:service name="MasterDataService">
<wsdl:port name="MasterDataPort" binding="ns0:MasterDataBinding">
<soap11:address location="https://webservices.post.ch:443/IN_MYPBxTT/services/MasterData.ws"/></wsdl:port>
<wsdl:port name="MasterDataPort.0" binding="ns0:MasterDataBinding">
<soap11:address location="https://webservices.post.ch:443/IN_MYPBxTT/services/MasterData.ws"/></wsdl:port></wsdl:service></wsdl:definitions>

我正在尝试使用此PHP

访问此文件
    // SOAP Configuration
$SOAP_wsdl_file_path = 'MasterData.xml';

$SOAP_config = array(
    // Webservice Endpoint URL
    'location' => 'https://webservices.post.ch/IN_MYPBxTT/services/TrackAndTraceDFU.ws',
    // Webservice Login
    'login' => $login,
    'password' => $pass,
);

// SOAP Connection
try {
    $SOAP_Client = new SoapClient($SOAP_wsdl_file_path, $SOAP_config);
} catch (SoapFault $fault) {
    die('<pre>Error in SOAP Initialization: '.$fault->__toString().'</pre>');
}

?>

这会产生此错误:

SoapFault exception: [WSDL] SOAP-ERROR: Parsing Schema: can't import schema 

from '/pathto/MasterData.ws.xsd1.xsd' in /pathto/request.php:22
Stack trace:
#0 /pathto/request.php(22): SoapClient->SoapClient('MasterData.xml', Array)
#1 {main}

我理解这个问题来自我使用xml文件而不是wsdl的事实,但无论如何我可以使用这个xml文件与SoapClient()或有没有办法将我的xml文件转换为wsdl使用用SoapClient()?

谢谢你,任何帮助都会有很大的帮助!

1 个答案:

答案 0 :(得分:0)

我不确定你到底需要什么。 WSDL文件也是XML文件,但相反的情况不适用。 XML是一种通用数据格式,可以包含任何类型的信息。 WSDL是用于描述Web服务的特定XML。

请检查wiki for further clarification。 不确定你有什么样的XML。它可能是测试数据,也可能是文件后缀不正确的WSDL。您需要检查文件的内容

可在此处找到示例WSDL文件: https://www.w3.org/2001/04/wsws-proceedings/uche/wsdl.html