КАК: PHP SoapClinet WSDL Структура параметров запроса - PullRequest
0 голосов
/ 21 декабря 2018

Я новичок в веб-сервисе SOAP.Имеется мыльный сервер с test.wsdl.Я хочу получить ответ от сервера и написать следующий скрипт PHP, чтобы получить результат.Однако в скрипте произошла ошибка и произошла следующая ошибка:

Невозможно обработать сообщение, так как тип содержимого 'application / soap + xml;кодировка = UTF-8;action = "ELevy.Service / IELevyService / LevyEFrank" 'не был ожидаемым типом' multipart / related;type = "application / xop + xml".

Может ли кто-нибудь помочь мне (или дать мне подсказку) для решения проблемы?

Спасибо заранее!

Вот test.wsdl:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="ELevyService" targetNamespace="ELevy.Service" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 

xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="ELevy.Service" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <wsp:Policy wsu:Id="BasicHttpsBinding_IELevyService_policy">
        <wsp:ExactlyOne>
            <wsp:All>
                <wsoma:OptimizedMimeSerialization xmlns:wsoma="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization"/>
                <sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
                    <wsp:Policy>
                        <sp:TransportToken>
                            <wsp:Policy>
                                <sp:HttpsToken RequireClientCertificate="false"/>
                            </wsp:Policy>
                        </sp:TransportToken>
                        <sp:AlgorithmSuite>
                            <wsp:Policy>
                                <sp:Basic256/>
                            </wsp:Policy>
                        </sp:AlgorithmSuite>
                        <sp:Layout>
                            <wsp:Policy>
                                <sp:Strict/>
                            </wsp:Policy>
                        </sp:Layout>
                    </wsp:Policy>
                </sp:TransportBinding>
            </wsp:All>
        </wsp:ExactlyOne>
    </wsp:Policy>
    <wsdl:types>
        <xs:schema elementFormDefault="qualified" targetNamespace="ELevy.Service" xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:import namespace="ELevy.Schema"/>
            <xs:element name="LevyEFrank">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="request" nillable="true" type="q1:LevyEFrankRequest" xmlns:q1="ELevy.Schema"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
            <xs:element name="LevyEFrankResponse">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element minOccurs="0" name="LevyEFrankResult" nillable="true" type="q2:LevyEFrankResponse" xmlns:q2="ELevy.Schema"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>
        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/"> 
            <xs:element name="anyType" nillable="true" type="xs:anyType"/>
            <xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
            <xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
            <xs:element name="boolean" nillable="true" type="xs:boolean"/>
            <xs:element name="byte" nillable="true" type="xs:byte"/>
            <xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
            <xs:element name="decimal" nillable="true" type="xs:decimal"/>
            <xs:element name="double" nillable="true" type="xs:double"/>
            <xs:element name="float" nillable="true" type="xs:float"/>
            <xs:element name="int" nillable="true" type="xs:int"/>
            <xs:element name="long" nillable="true" type="xs:long"/>
            <xs:element name="QName" nillable="true" type="xs:QName"/>
            <xs:element name="short" nillable="true" type="xs:short"/>
            <xs:element name="string" nillable="true" type="xs:string"/>
            <xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
            <xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
            <xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
            <xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
            <xs:element name="char" nillable="true" type="tns:char"/>
            <xs:simpleType name="char">
                <xs:restriction base="xs:int"/>
            </xs:simpleType>
            <xs:element name="duration" nillable="true" type="tns:duration"/>
            <xs:simpleType name="duration">
                <xs:restriction base="xs:duration">
                    <xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
                    <xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
                    <xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
                </xs:restriction>
            </xs:simpleType>
            <xs:element name="guid" nillable="true" type="tns:guid"/>
            <xs:simpleType name="guid">
                <xs:restriction base="xs:string">
                    <xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
                </xs:restriction>
            </xs:simpleType>
            <xs:attribute name="FactoryType" type="xs:QName"/>
            <xs:attribute name="Id" type="xs:ID"/>
            <xs:attribute name="Ref" type="xs:IDREF"/>
        </xs:schema>
        <xs:schema elementFormDefault="qualified" targetNamespace="ELevy.Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="ELevy.Schema">
            <xs:complexType name="LevyEFrankRequest">
                <xs:sequence>
                    <xs:element name="API_KEY" nillable="true" type="xs:string"/>
                    <xs:element name="RECEIPT_NUMBER" nillable="true" type="xs:string"/>
                    <xs:element name="OUT_BOUND_FARE_PAID" nillable="true" type="xs:string"/>
                    <xs:element name="NAME_OF_TRAVELER_PAYER" nillable="true" type="xs:string"/>
                    <xs:element name="DEPARTURE_DATE" nillable="true" type="xs:string"/>
                    <xs:element name="LAST_4_DIGIT_OF_CONTACT_PHONE_NUMBER" nillable="true" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="LevyEFrankRequest" nillable="true" type="tns:LevyEFrankRequest"/>
            <xs:complexType name="LevyEFrankResponse">
                <xs:sequence>
                    <xs:element name="ACK_CODE" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="ACK_MESSAGE" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="RECEIPT_NUMBER" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="OUT_BOUND_FARE_PAID" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="NAME_OF_TRAVELER_PAYER" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="DEPARTURE_DATE" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="LAST_4_DIGIT_OF_CONTACT_PHONE_NUMBER" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="FRANK_DATE_TIME" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="LEVY_COLLECTION_NUMBER" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="LEVY_AMOUNT" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="LOW_ACCOUNT_BALANCE_INDICATOR" nillable="true" type="xs:string"/>
                    <xs:element minOccurs="0" name="LEVY_STAMP" nillable="true" type="xs:base64Binary"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="LevyEFrankResponse" nillable="true" type="tns:LevyEFrankResponse"/>
        </xs:schema>
    </wsdl:types>
    <wsdl:message name="IELevyService_LevyEFrank_InputMessage">
        <wsdl:part name="parameters" element="tns:LevyEFrank"/>
    </wsdl:message>
    <wsdl:message name="IELevyService_LevyEFrank_OutputMessage">
        <wsdl:part name="parameters" element="tns:LevyEFrankResponse"/>
    </wsdl:message>
    <wsdl:portType name="IELevyService">
        <wsdl:operation name="LevyEFrank">
            <wsdl:input wsaw:Action="ELevy.Service/IELevyService/LevyEFrank" message="tns:IELevyService_LevyEFrank_InputMessage"/>
            <wsdl:output wsaw:Action="ELevy.Service/IELevyService/LevyEFrankResponse" message="tns:IELevyService_LevyEFrank_OutputMessage"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="BasicHttpBinding_IELevyService" type="tns:IELevyService">
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="LevyEFrank">
            <soap:operation soapAction="ELevy.Service/IELevyService/LevyEFrank" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:binding name="BasicHttpsBinding_IELevyService" type="tns:IELevyService">
        <wsp:PolicyReference URI="#BasicHttpsBinding_IELevyService_policy"/>
        <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="LevyEFrank">
            <soap:operation soapAction="ELevy.Service/IELevyService/LevyEFrank" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="ELevyService">
        <wsdl:port name="BasicHttpBinding_IELevyService" binding="tns:BasicHttpBinding_IELevyService">
            <soap:address location="http://localhost/ELevyService.svc"/>
        </wsdl:port>
        <wsdl:port name="BasicHttpsBinding_IELevyService" binding="tns:BasicHttpsBinding_IELevyService">
            <soap:address location="https://localhost/ELevyService.svc"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Вот PHP-скрипт index.php:

<?php
// initialize soap client
$soapOption = array(
    'soap_version' => SOAP_1_2,
    'location' => 'https://www.elevy-ticf-train.org.hk:8443/ELevyService.svc'
);

$client = new SoapClient('test.wsdl', $soapOption);
$error  = 0;

// request parameters
$soapCallParameters = new stdClass();
$soapCallParameters->API_KEY = '87062F452DD245E89661F5A2E9F8720A';
$soapCallParameters->RECEIPT_NUMBER = '201800001';
$soapCallParameters->OUT_BOUND_FARE_PAID = '105.65';
$soapCallParameters->NAME_OF_TRAVELER_PAYER = "Anonymous";
$soapCallParameters->DEPARTURE_DATE = "2018-12-31";
$soapCallParameters->LAST_4_DIGIT_OF_CONTACT_PHONE_NUMBER = '3775';

// for debugging
$functions = $client->__getFunctions();
$types = $client->__getTypes();

// debugging status
var_dump($functions);
var_dump($types);
var_dump($client);

try {
    $result = $client->LevyEFrank($soapCallParameters);

} catch (SoapFault $fault) {
    $error = 1;
}

if ($error == 1) {
    var_dump($fault->faultcode);
    var_dump($fault->faultstring);
} else {
    var_dump($result);
}

var_dump () PHP-скрипта:

D:\Wamp64\www\a\index.php:24:
array (size=2)
  0 => string 'LevyEFrankResponse LevyEFrank(LevyEFrank $parameters)' 
(length=53)
  1 => string 'LevyEFrankResponse LevyEFrank(LevyEFrank $parameters)' 
(length=53)
D:\Wamp64\www\a\index.php:25:
array (size=7)
  0 => string 'struct LevyEFrank {
 LevyEFrankRequest request;
}' (length=49)
  1 => string 'struct LevyEFrankResponse {
 LevyEFrankResponse LevyEFrankResult;
}' (length=67)
  2 => string 'int char' (length=8)
  3 => string 'duration duration' (length=17)
  4 => string 'string guid' (length=11)
  5 => string 'struct LevyEFrankRequest {
 string API_KEY;
 string RECEIPT_NUMBER;
 string OUT_BOUND_FARE_PAID;
 string NAME_OF_TRAVELER_PAYER;
 string DEPARTURE_DATE;
 string LAST_4_DIGIT_OF_CONTACT_PHONE_NUMBER;
}' (length=200)
  6 => string 'struct LevyEFrankResponse {
 string ACK_CODE;
 string ACK_MESSAGE;
 string RECEIPT_NUMBER;
 string OUT_BOUND_FARE_PAID;
 string NAME_OF_TRAVELER_PAYER;
 string DEPARTURE_DATE;
 string LAST_4_DIGIT_OF_CONTACT_PHONE_NUMBER;
 string FRANK_DATE_TIME;
 string LEVY_COLLECTION_NUMBER;
 string LEVY_AMOUNT;
 string LOW_ACCOUNT_BALANCE_INDICATOR;
 base64Binary LEVY_STAMP;
}' (length=366)

D:\Wamp64\www\a\index.php:26:
object(SoapClient)[1]
  public 'location' => string 'https://www.elevy-ticf-train.org.hk:8443/ELevyService.svc' (length=57)
  public '_stream_context' => resource(2, stream-context)
  public '_soap_version' => int 2
  public 'sdl' => resource(4, SOAP SDL)

D:\Wamp64\www\a\index.php:36:string 'HTTP' (length=4)

D:\Wamp64\www\a\index.php:37:string 'Cannot process the message because 
the content type 'application/soap+xml; charset=utf-8; 
action="ELevy.Service/IELevyService/LevyEFrank"' was not the expected 
type 'multipart/related; type="application/xop+xml"'.' (length=213)
...