Soap - how?

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I have never used PHP's SOAP to do anything so I am seriously unfamiliar with the formatting of a proper SOAP call. The documentation on the server I am using states that I need to first do a "login" request and then I will receive my "token" which I need to use for the rest of my transactions with this server.

So First, the login function; The documentation states the call should look as follows:

XML Code: [ Select ]
POST /poswebservice/V3DataAccess.asmx HTTP/1.1
Host: <!-- m --><span class="postlink">http://www.ticketbreak.co.za</span><!-- m -->
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx/Login"
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <Login xmlns="http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx">
      <UserName>string</UserName>
      <Password>string</Password>
    </Login>
  </soap:Body>
</soap:Envelope>
  1. POST /poswebservice/V3DataAccess.asmx HTTP/1.1
  2. Host: <!-- m --><span class="postlink">http://www.ticketbreak.co.za</span><!-- m -->
  3. Content-Type: text/xml; charset=utf-8
  4. Content-Length: length
  5. SOAPAction: "http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx/Login"
  6.  
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  9.   <soap:Body>
  10.     <Login xmlns="http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx">
  11.       <UserName>string</UserName>
  12.       <Password>string</Password>
  13.     </Login>
  14.   </soap:Body>
  15. </soap:Envelope>


The WSDL for this function looks as follows:

XML Code: [ Select ]
<s:element name="Login">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/>
   <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
  </s:sequence>
 </s:complexType>
</s:element>
<s:element name="LoginResponse">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="0" maxOccurs="1" name="LoginResult">
    <s:complexType>
     <s:sequence>
      <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
      <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
     </s:sequence>
     <s:attribute fixed="http://www.ticketbreak.com/Accounts.xsd" name="namespace"/>
     <s:attribute fixed="AccountsDataTable" name="tableTypeName"/>
    </s:complexType>
   </s:element>
  </s:sequence>
 </s:complexType>
</s:element>
  1. <s:element name="Login">
  2.  <s:complexType>
  3.   <s:sequence>
  4.    <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string"/>
  5.    <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
  6.   </s:sequence>
  7.  </s:complexType>
  8. </s:element>
  9. <s:element name="LoginResponse">
  10.  <s:complexType>
  11.   <s:sequence>
  12.    <s:element minOccurs="0" maxOccurs="1" name="LoginResult">
  13.     <s:complexType>
  14.      <s:sequence>
  15.       <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
  16.       <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
  17.      </s:sequence>
  18.      <s:attribute fixed="http://www.ticketbreak.com/Accounts.xsd" name="namespace"/>
  19.      <s:attribute fixed="AccountsDataTable" name="tableTypeName"/>
  20.     </s:complexType>
  21.    </s:element>
  22.   </s:sequence>
  23.  </s:complexType>
  24. </s:element>


I call the login function successfully with the following code:

PHP Code: [ Select ]
$client = new SoapClient('http://www.ticketbreak.co.za/poswebservice/V3DataAccess.asmx?WSDL');
  $result = $client->login(
    array(
      'UserName' => 'username@email.extension',
      'Password' => 'password'
    )
  );
  $temp_return = $result->LoginResult->any;
  $end_stripping = strpos($temp_return,'</xs:schema>')+12;
  $temp_return = substr($temp_return,$end_stripping,(strlen($temp_return) - $end_stripping));
  $xml = simplexml_load_string($temp_return);
  $token = $xml->DocumentElement->Accounts->AuthUserID;
  1. $client = new SoapClient('http://www.ticketbreak.co.za/poswebservice/V3DataAccess.asmx?WSDL');
  2.   $result = $client->login(
  3.     array(
  4.       'UserName' => 'username@email.extension',
  5.       'Password' => 'password'
  6.     )
  7.   );
  8.   $temp_return = $result->LoginResult->any;
  9.   $end_stripping = strpos($temp_return,'</xs:schema>')+12;
  10.   $temp_return = substr($temp_return,$end_stripping,(strlen($temp_return) - $end_stripping));
  11.   $xml = simplexml_load_string($temp_return);
  12.   $token = $xml->DocumentElement->Accounts->AuthUserID;


The next function I then need to call is GetEventInformation and this is where I am having trouble, the documentation states that the call should look as follows:

XML Code: [ Select ]
POST /poswebservice/V3DataAccess.asmx HTTP/1.1
Host: <!-- m --><span class="postlink">http://www.ticketbreak.co.za</span><!-- m -->
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx/GetEventInformation"
 
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetEventInformation xmlns="http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx">
      <Token>
        <UserName>string</UserName>
        <Token>string</Token>
      </Token>
      <EventID>int</EventID>
    </GetEventInformation>
  </soap:Body>
</soap:Envelope>
  1. POST /poswebservice/V3DataAccess.asmx HTTP/1.1
  2. Host: <!-- m --><span class="postlink">http://www.ticketbreak.co.za</span><!-- m -->
  3. Content-Type: text/xml; charset=utf-8
  4. Content-Length: length
  5. SOAPAction: "http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx/GetEventInformation"
  6.  
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  9.   <soap:Body>
  10.     <GetEventInformation xmlns="http://www.ticketbreak.com/poswebservice/V3DataAccess.asmx">
  11.       <Token>
  12.         <UserName>string</UserName>
  13.         <Token>string</Token>
  14.       </Token>
  15.       <EventID>int</EventID>
  16.     </GetEventInformation>
  17.   </soap:Body>
  18. </soap:Envelope>


The WSDL on this function looks as follows:

XML Code: [ Select ]
<s:element name="GetEventInformation">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="1" maxOccurs="1" name="Token" type="tns:SecurityToken"/>
   <s:element minOccurs="1" maxOccurs="1" name="EventID" type="s:int"/>
  </s:sequence>
 </s:complexType>
</s:element>
<s:element name="GetEventInformationResponse">
 <s:complexType>
  <s:sequence>
   <s:element minOccurs="0" maxOccurs="1" name="GetEventInformationResult">
    <s:complexType>
     <s:sequence>
      <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
      <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
     </s:sequence>
     <s:attribute fixed="http://www.ticketbreak.com/Events.xsd" name="namespace"/>
     <s:attribute fixed="EventsDataTable" name="tableTypeName"/>
    </s:complexType>
   </s:element>
  </s:sequence>
 </s:complexType>
</s:element>
  1. <s:element name="GetEventInformation">
  2.  <s:complexType>
  3.   <s:sequence>
  4.    <s:element minOccurs="1" maxOccurs="1" name="Token" type="tns:SecurityToken"/>
  5.    <s:element minOccurs="1" maxOccurs="1" name="EventID" type="s:int"/>
  6.   </s:sequence>
  7.  </s:complexType>
  8. </s:element>
  9. <s:element name="GetEventInformationResponse">
  10.  <s:complexType>
  11.   <s:sequence>
  12.    <s:element minOccurs="0" maxOccurs="1" name="GetEventInformationResult">
  13.     <s:complexType>
  14.      <s:sequence>
  15.       <s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax"/>
  16.       <s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax"/>
  17.      </s:sequence>
  18.      <s:attribute fixed="http://www.ticketbreak.com/Events.xsd" name="namespace"/>
  19.      <s:attribute fixed="EventsDataTable" name="tableTypeName"/>
  20.     </s:complexType>
  21.    </s:element>
  22.   </s:sequence>
  23.  </s:complexType>
  24. </s:element>


I am using the following code currently:

PHP Code: [ Select ]
$result_tickets = $client->GetEventInformation(
    array(
      'Token' => array(
        'Username' => 'username@email.extension',
        'Token' => $token
      ),
      'EventID' => 1140
    )
  );
echo '<pre>',print_r($result_tickets),'</pre><br /><br />';
  1. $result_tickets = $client->GetEventInformation(
  2.     array(
  3.       'Token' => array(
  4.         'Username' => 'username@email.extension',
  5.         'Token' => $token
  6.       ),
  7.       'EventID' => 1140
  8.     )
  9.   );
  10. echo '<pre>',print_r($result_tickets),'</pre><br /><br />';


But all this code returns is an empty object:

Code: [ Select ]
stdClass Object
(
)
1
  1. stdClass Object
  2. (
  3. )
  4. 1


It feels to me like the format of the array I am sending to the GetEventInformation is not correctly formatted ... ? Or Am I supposed to send the headers with?? And if I do need to send the headers, how would that be formatted?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

Wooohoo ... I figured this out, what a dumb mistake "Username" should've been "UserName".
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

righteous_trespasser wrote:
Wooohoo ... I figured this out, what a dumb mistake "Username" should've been "UserName".

Bah! These mistakes always get you.

Glad you got it working
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6249
  • Loc: Seattle, WA

Post 3+ Months Ago

Ugh. Don't use SOAP. Seriously.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

spork wrote:
Ugh. Don't use SOAP. Seriously.

I don't really have a choice here, I think ... is there an alternative? This is something that I've never done before so I actually have no idea ...
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6249
  • Loc: Seattle, WA

Post 3+ Months Ago

REST, or if you must use an RPC framework, XML-RPC is a good alternative to SOAP.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

SOAP bashing are we? Personally I have no issues with SOAP. I developed a large scale SOA using SOAP. I have also done the RESTful services and the XML-RPC services. In my opinion if you want to can anything it would be XML-RPC :) All XML-RPC does is allow you to pass through XML. It doesn't enforce anything and when developing against a third party this can be particullarly hazardous to one's sanity :) SOAP uses the XSDs to enforce the fact that your message is well formatted and compliant with the expected message. If you really want to get into distributed computing then ditch the REST, SOAP and XML-RPC and look into CORBA
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1240
  • Loc: Sydney

Post 3+ Months Ago

never seen this SOAP apart from in the shower? hhmm think it is google time

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 74 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.