Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Load the classes constructed by wsdl2php
- require_once 'ecmasService.php';
- // Define the SOAP options.
- $a_SoapOptions = array
- (
- 'encoding' => 'UTF-8',
- 'exception' => True, // Turn SOAPFaults into Exceptions so PHP can report upon them.
- 'trace' => True, // Turn on tracing so we can see EXACTLY what the headers and request/response are.
- );
- // As we are going to need to display XML, use Tidy to make it pretty.
- $a_TidyConfig = array
- (
- 'indent' => 4,
- 'indent-attributes' => true,
- 'input-xml' => true,
- 'output-xml' => true,
- 'wrap' => 0,
- );
- $o_Tidy = new Tidy;
- $s_WsdlUrl = "a.wsdl"; // Using a local edited copy of the wsdl you posted.
- // Use a try/catch loop to talk to the services.
- try
- {
- // Create a service.
- $o_Service = new ecmasService($s_WsdlUrl, $a_SoapOptions);
- // Create the parameters
- $o_UserLoginParams = new userLogin;
- $o_UserLoginParams->username = 'MyUsername';
- $o_UserLoginParams->password = 'MyPassword';
- // Call the method.
- $o_UserLoginResponse = $o_Service->userLogin($o_UserLoginParams);
- // Extract the results.
- $s_Token = $o_UserLoginResponse->token;
- // For some services, the results are raw XML and not a WSDL provided complex type. If this is the case, convert the XML to a simplexml object.
- // $o_HelloWorldResults = simplexml_load_string($o_HelloWorldResponse->HelloWorldResult;);
- // Display the results as they are.
- echo PHP_EOL,
- // Show trace.
- 'Request Headers', PHP_EOL,
- '---------------', PHP_EOL,
- $o_Service->__getLastRequestHeaders(), PHP_EOL,
- 'Request', PHP_EOL,
- '-------', PHP_EOL,
- $o_Tidy->repairString($o_Service->__getLastRequest(), $a_TidyConfig), PHP_EOL, PHP_EOL,
- 'Response Headers', PHP_EOL,
- '----------------', PHP_EOL,
- $o_Service->__getLastResponseHeaders(), PHP_EOL,
- 'Response', PHP_EOL,
- '--------', PHP_EOL,
- $o_Tidy->repairString($o_Service->__getLastResponse(), $a_TidyConfig), PHP_EOL, PHP_EOL, PHP_EOL,
- 'Response interpreted', PHP_EOL,
- '--------------------', PHP_EOL,
- print_r($s_Token, True), PHP_EOL;
- }
- catch(Exception $e)
- {
- echo PHP_EOL,
- // Show trace.
- 'Request Headers', PHP_EOL,
- '---------------', PHP_EOL,
- $o_Service->__getLastRequestHeaders(), PHP_EOL,
- 'Request', PHP_EOL,
- '-------', PHP_EOL,
- $o_Tidy->repairString($o_Service->__getLastRequest(), $a_TidyConfig), PHP_EOL, PHP_EOL,
- 'Response Headers', PHP_EOL,
- '----------------', PHP_EOL,
- $o_Service->__getLastResponseHeaders(), PHP_EOL,
- 'Response', PHP_EOL,
- '--------', PHP_EOL,
- $o_Tidy->repairString($o_Service->__getLastResponse(), $a_TidyConfig), PHP_EOL, PHP_EOL, PHP_EOL,
- // Show exception.
- 'Exception', PHP_EOL,
- '---------', PHP_EOL,
- $e->getMessage(), PHP_EOL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement