Interfaces/Mac SOAP Client

From J Wiki
Jump to navigation Jump to search
Webobjects20050720.gif

We shall explore how to consume the Web Service defined in Windows with clients in Mac OS X.

Discovering Web Service

A great tool for doing web service discovery on Mac is SOAP Client.

We run the SOAP Client and point it to our JApp service, using the URL
   http://host/JApp/JDLLServer.3.soap?WSDL.

SoapClient.png

It quickly parses the WSDL and fills out the necessary detail: Service name and list of methods; and for each method: Endpoint URI, SOAP Action, Namespace and parameters.

It is ready to execute DoR method with i.2 3 input parameter:

Host: host
User-Agent: Mac OS X; WebServicesCore.framework (1.1.0)
Content-Type: text/xml
Soapaction: http://schemas.microsoft.com/clr/nsassem/JDLLServerLib.JDLLServerClass/JDLLServerLib#DoR

<?xml version="1.0" encoding="UTF-8"?>
  <SOAP-ENV:Envelope
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
      <SOAP-ENV:Body>
        <m:DoR xmlns:m="http://schemas.microsoft.com/clr/nsassem/JDLLServerLib/JDLLServerLib%2C%20Version%3D3.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3D4a20487b5a2222ad">
          <input xsi:type="xsd:string">i.2 3</input>
        </m:DoR>
      </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

which returns the following response.

HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1, MS .NET Remoting, MS .NET CLR 2.0.50727.42
Connection: close
X-Aspnet-Version: 2.0.50727
Date: Sun, 15 Apr 2007 11:15:40 GMT
Content-Length: 952
Cache-Control: private
Content-Type: text/xml; charset="utf-8"

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Header>
    <h4:__CallContext href="#ref-3" xmlns:h4="http://schemas.microsoft.com/clr/soap/messageProperties" SOAP-ENC:root="1"/>
    <a1:LogicalCallContext id="ref-3" xmlns:a1="http://schemas.microsoft.com/clr/ns/System.Runtime.Remoting.Messaging">
    </a1:LogicalCallContext>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <i5:DoRResponse id="ref-1" xmlns:i5="http://schemas.microsoft.com/clr/nsassem/JDLLServerLib.JDLLServerClass/JDLLServerLib">
      <return>0</return>
      <v id="ref-6" xsi:type="SOAP-ENC:string">0 1 2
3 4 5
</v>
    </i5:DoRResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Not only strings can be passed over. In fact all the powerful COM Variant marshalling with Get/Set methods are passed on to SOAP types.

Here we assign i.2 3 to name a and use Get to obtain the value of a. The body of response looks like this (note two-dimensional array representation as int[2,3]:

<i5:GetResponse id="ref-1" xmlns:i5="http://schemas.microsoft.com/clr/nsassem/JDLLServerLib.JDLLServerClass/JDLLServerLib">
  <return>0</return>
  <v href="#ref-6"/>
</i5:GetResponse>
<SOAP-ENC:Array id="ref-6" SOAP-ENC:arrayType="xsd:int[2,3]">
  <item>0</item>
  <item>1</item>
  <item>2</item>
  <item>3</item>
  <item>4</item>
  <item>5</item>
</SOAP-ENC:Array>

Automator Web Service Client

Automator has an action for calling web services, which will be used with discovery parameters above to call J SOAP service.

The workflow consists of three actions:

  • Run AppleScript (Get J Input)
on run {input, parameters}
	display dialog "Enter J expression" default answer "i.2 3"
	return {input:text returned of result}
end run
  • Run Web Service (J SOAP Service)

AutomatorWebClient.png

  • Run AppleScript (Show J Response)
on run {input, parameters}
	display alert "J Responded" message (get v of item 2 of input)
	return input
end run

The SOAP input and results as AppleScript objects in a couple of Automator sessions

AutoSess1.png AutoSess2.png
{{input:"] b=: 2 3 ?@$ 0"}, {v:"0.971379 0.0466292 0.330109

0.01346 0.220004 0.600044", |return|:"0"}}

{{input:"+/ b"}, {v:"0.984839 0.266633 0.930153", |return|:"0"}}

See Also