Accessing Web services using the HTTP GET Protocol |
Top Previous Next |
In addition to accessing Web services by exchanging SOAP envelopes using the HTTP POST protocol, SOAP/AM Server also allows the use of the HTTP GET protocol to access Web services. Using the HTTP GET protocol can be more convenient when developing client application that are browser based ... typically referred to as AJAX applications. When accessing a service via HTTP GET there are some considerations and restrictions:
Web service methods can be invoked by simply appending the method name to the Web service endpoint URL and providing the method parameters as query string arguments. For example, the Echo String sample service that is provided with SOAP/AM Server can be accessed at the endpoint URL:
http://mysystem:port/services/samples/echostring/echostring
The service's echoString method has the following signature:
return = echoString(inputString)
Using this information the following URL can be used to invoke the echoString method and echo the string "hello world!":
http://mysystem:port/services/samples/echostring/echostring/echoString?inputString=hello world!
Accessing this URL from a browser (which uses the HTTP GET protocol) yields the following result:
<echoStringResponse xmlns="http://soapam.nuwave-tech.com/services/echostring/echostring/"> <return>hello world!</return> </echoStringResponse>
Note that although the response from an HTTP GET request is an XML stream, it is not wrapped in a SOAP envelope. This makes it somewhat easier to parse the response. SOAP/AM Server can also return the response as a JavaScript Object Notation (JSON) stream. Appending the argument "jsonresult=1" to the query string instructs SOAP/AM Server that a JSON result is desired. For example, the URL:
http://mysystem:port/services/samples/echostring/echostring/echoString?inputString=hello world!&jsonresult=1
Yields the following result:
{ 'return': 'hello world!' }
The JSON result can be parsed into JavaScript objects using the eval function. The following JavaScript fragment parses and displays the result:
var resultObject = eval('(' + jsonresultstream + ')'); alert(resultObject.return);
For more information on using JSON in AJAX applications visit the JSON page at Wikipedia.org or the JSON Web site.
|