简体   繁体   中英

SOAP request with PHP using an xml file instead of wsdl

I am trying to use a webservice (Swiss Post Track consignments) to update Prestashop order statuses to delivered on delivery.

The file that I have been given for requests looks like this (.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>

And I am trying to acces this file with this 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>');
}

?>

This generates this error:

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}

I understand this problem comes from the fact I am using a xml file instead of a wsdl, but is there anyway I can use this xml file with SoapClient() or is there a way to convert my xml file to wsdl for use with SoapClient() ?

Thank you, any help would be much appreaciated !

I'm Not sure what exactly you need. WSDL files are also XML files, but the opposite does not apply. XML is a generic data format, which can contain any kind of information. WSDL is a specific XML used for describing web services.

Please check wiki for further clarification . Not sure what kind of XML you have. It may be test data, or WSDLs with incorrect file suffix. You need to check the content of the files

Sample WSDL file can be found here: https://www.w3.org/2001/04/wsws-proceedings/uche/wsdl.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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