Solved

Help with SOAP Request

Posted on 2010-11-24
7
409 Views
Last Modified: 2012-05-10
I'm new to SOAP and really don't understand how to use it.  Can I get an example how to call for a request with the below code. They offer the WSDL but that confuses me even more.

http://bsn.wrx-us.com/MCmdWebservice/MCWebService.asmx?WSDL
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?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>
    <SendRTSCmdToModemResponse xmlns="https://bsn.wrx-us.com/MCmdWebService/">
      <SendRTSCmdToModemResult>string</SendRTSCmdToModemResult>
    </SendRTSCmdToModemResponse>
  </soap:Body>
</soap:Envelope>

Open in new window

POST /MCmdWebservice/MCWebService.asmx HTTP/1.1
Host: bsn.wrx-us.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://bsn.wrx-us.com/MCmdWebService/SendRTSCmdToModem"

<?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:Header>
    <Authentication xmlns="https://bsn.wrx-us.com/MCmdWebService/">
      <Username>string</Username>
      <Password>string</Password>
    </Authentication>
  </soap:Header>
  <soap:Body>
    <SendRTSCmdToModem xmlns="https://bsn.wrx-us.com/MCmdWebService/">
      <_sModemId>string</_sModemId>
      <_sCmd>string</_sCmd>
      <_iResp>int</_iResp>
    </SendRTSCmdToModem>
  </soap:Body>
</soap:Envelope>

Open in new window

0
Comment
Question by:thaburner
  • 4
  • 3
7 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 34206464
Just a thought - avoid SOAP whenever you can and choose a RESTful interface instead.  You can read the wikipedia article on REST here:
http://en.wikipedia.org/wiki/Representational_State_Transfer

A good example of a RESTful web service is the Yahoo Geocoder or Placefinder:
http://developer.yahoo.com/geo/placefinder/

When you see how easy REST is compared to SOAP, you will wonder why anyone would ever use SOAP!
0
 

Author Comment

by:thaburner
ID: 34207677
My vendor is telling me I have to use SOAP that their server can not handle REST. I have found this site www.ApiGenerator.com and generated a class and think I got it working to an extent but I get an error.

Error Returned: (SendRTSCmdToModem) SOAP Error: - SOAP-ERROR: Encoding: object hasn't '_iResp' property
<?php

/**
 * 
 * Generated Proxy Class : MyGoogleClass (to interact with SOAP server at http://bsn.wrx-us.com/MCmdWebservice/MCWebService.asmx?WSDL)
 * @package MyGoogle
 * @version 1.00
 * @author www.ApiGenerator.com - Copyright (c) 2010. All rights reserved.
 * 
 * We take no responsibility for the accuracy of this generated code. Use or edit at your own risk.
 * 
 */
	
class MySOAP {
var $client = null;
var $soapUrl = 'http://bsn.wrx-us.com/MCmdWebservice/MCWebService.asmx?WSDL';
var $options = array(); 

/**
 * 
 * Class: MyGoogle - Construct Method
 * 
 */

function __construct()
{
$this->client = new SoapClient($this->soapUrl, $this->options);
//Insert Additional Constructor Code
}

/**
 * 
 * Class: MyGoogle - Destruct Method
 * 
 */

function __destruct()
{
unset ($this->client);
//Insert Destructor Code
}



//This is the one i need
function SendRTSCmdToModem($parameters ){
	try {
		$funcRet = $this->client->SendRTSCmdToModem($parameters );
	} catch ( Exception $e ) {
		echo '(SendRTSCmdToModem) SOAP Error: - ' . $e->getMessage ();
	}
	return $funcRet; 
}

		
}

?>

Open in new window

include("MySOAP.class.php");
$Request = new MySOAP();

$Data['Authentication'] = array('Username' => 'usr','Password' => 'pwd');
$Data['SendRTSCmdToModem'] = array('_sModemId' => '123456','_sCmd' => 'battery','_iResp' => '0');
	
echo $Request->SendRTSCmdToModem($Data);

Open in new window

0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34207731
Regarding this, "My vendor is telling me I have to use SOAP that their server can not handle REST."  That's ridiculous.  Your vendor does not know what she is talking about.  The WWW is a RESTful interface, so if they have a web site, they are already using REST!

The advantage of a RESTful interface is that every request is atomic and complete.  You put in a URL and you get back a web page.  It really is that simple.

Anyway, you might try removing '_iResp' => '0' from the second array.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:thaburner
ID: 34208144
The vendor is now closed for holidays, I will talk to someone else to see if they know what they are talking about. In the mean time I removed it from the Array and it still gives me the same error.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34208900
Bummer.  Yeah, that is the kind of thing that you get with SOAP.  You wind up having to debug systems that run on another computer -- and you don't have any access to the other computer.
0
 

Author Comment

by:thaburner
ID: 34208985
Well far as I'm concerned SOAP is crap. Thanks for your help.
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 34209055
Thanks for the points.  I agree with your assessment: crap.  In contrast to SOAP, here is an example of a RESTful web service.  If you put your URL behind HTTPS, your API keys will be hidden from view, and it will still be easy to use!
<?php // RAY_REST_get_last_name.php
error_reporting(E_ALL);



// DEMONSTRATE HOW A RESTFUL WEB SERVICE WORKS
// INPUT FIRST NAME, OUTPUT LAST NAME
// CALLING EXAMPLE:
// file_get_contents('http://laprbass.com/RAY_REST_get_last_name.php?key=ABC&resp=XML&name=Ray');



// OUR DATA MODEL CONTAINS ALL THE ANSWERS - THIS COULD BE A DATA BASE - AS SIMPLE OR COMPLEX AS NEEDED
$dataModel
= array
( 'Brian'   => 'Portlock'
, 'Ray'     => 'Paseur'
, 'Richard' => 'Quadling'
, 'Dave'    => 'Baldwin'
)
;


// SHOULD RESPONSE BE PLAIN TEXT OR XML FORMAT
$alpha = '';
$omega = '';
if ( (isset($_GET["resp"])) && ($_GET["resp"] == 'XML') )
{
    $alpha = '<response>';
    $omega = '</response>';
}



// TEST THE API KEY
$key = FALSE;
if (isset($_GET["key"])) $key = $_GET["key"];
if ($key !== 'ABC') die($alpha . 'BOGUS API KEY' . $omega);



// LOOK UP THE LAST NAME
$name="?";
if (isset($_GET["name"])) $name = $_GET["name"];

// IF THE URL NAME IS FOUND IN THE DATA MODEL
if (array_key_exists($name, $dataModel))
{
    // RETURNS THE LAST NAME FROM THE DATA MODEL
    die($alpha . "$dataModel[$name]" . $omega);
}

// RETURNS THE UNKNOWN NAME INDICATOR
else die($alpha . 'UNKNOWN' . $omega);

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question