PHP - 没有按预期解析Soap xml

I'm working with webservices (OTRS webservices to be precise). I'm using PHP5 soapClient and (for future reference) this is the result of dump($client->__getFunctions()); ($client is my object created with the WSDL and url where the webservice server side is running)

array:5 [
  0 => "OTRS_TicketCreateResponse TicketCreate(OTRS_TicketCreate $TicketCreate)"
  1 => "OTRS_TicketUpdateResponse TicketUpdate(OTRS_TicketUpdate $TicketUpdate)"
  2 => "OTRS_TicketGetResponse TicketGet(OTRS_TicketGet $TicketGet)"
  3 => "OTRS_TicketSearchResponse TicketSearch(OTRS_TicketSearch $TicketSearch)"
  4 => "OTRS_SessionCreateResponse SessionCreate(OTRS_SessionCreate $SessionCreate)"

Note: I want to call the last service SessionCreate

Also the result of dump($client->__getTypes()); - only for the web service request I'm trying to call (to avoid a huge wall of text).

 21 => """
    struct OTRS_SessionCreate {
     string UserLogin;
     string CustomerUserLogin;
     string Password;

The WSDL file shows this for the SessionCreate

<xsd:complexType name="OTRS_SessionCreate">
          <xsd:choice minOccurs="1" maxOccurs="1">
              <xsd:documentation>UserLogin or CustomerUserLogin is mandatory.</xsd:documentation>
            <xsd:element name="UserLogin" type="xsd:string" minOccurs="0"/>
            <xsd:element name="CustomerUserLogin" type="xsd:string" minOccurs="0"/>
          <xsd:element name="Password" type="xsd:string" minOccurs="0"/>

My PHP code

$client->SessionCreate("SessionCreate", array("SessionCreate" => array("UserLogin" => "Myuser","Password" => "secret")));

If I do dump($client->__getLastRequest());

<?xml version="1.0" encoding="UTF-8"?>
  <SOAP-ENV:Envelope xmlns:SOAP-ENV=""><SOAP-ENV:Body><SessionCreate/><param1><item><key>SessionCreate</key><value><item><key>UserLogin</key><value>myuser</value></item><item><key>Password</key><value>secret</value></item></value></item></param1></SOAP-ENV:Body></SOAP-ENV:Envelope>

what I actually need to send is:

<soapenv:Envelope xmlns:soapenv="">
         <!--You have a CHOICE of the next 2 items at this level-->

My question

I've tried several ways to feed the data into the soapCall - through arrays, objects, even hand crafted the XML. What I want is for it to receive a SessionCreate tag with a tag for UserLogin and another one for Password, each containing the data. But no matter what I try, PHP will always wrap with the <param1> and so on, and also always have an empty <SessionCreate> (by just writing <SessionCreate/>

So my two part question is: * How do I properly feed the object into the SOAP call? * Is there a way I can statically declare the XML and make a SOAP call with it? Even if I had to have a $xml = "<soapEnvelope>" and whatnot... and then just call something like $client->soapCall(url,xml)


I encountered The secret that's the miracle cure (and thought I'd share it here for future desperate coders in need to scratch their webservices hitch). It's the SoapParam object.

Note: NameOfService is the first wrapper tag that names the service.

$response = $client->__soapCall("NameOfService", array(
new SoapParam("value1", "nameOfTag"),
new SoapParam("value2","nameOfSecondTag"),
// ... so on and so forth for all the parameters you require to send

$response will be populated with whatever your webservice returns.

Csdn user default icon