Interfaces/SOAP Call

From J Wiki
Jump to navigation Jump to search

Using Scripts/HTTP Get utility J can be used as a client to a SOAP Web Service.

Here we will use an explicit definition of a SOAP body and HTTP request, which is obtained from a SOAP Client utility.

soapBody=: 0 : 0
<?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">%1</input>
  </m:DoR>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
)

Note: the actual value is represented as parameter %1, which is substituted using the wrapper verb.

soapTest=: 3 : 0
  require 'user/httpget.ijs regex'
Heads_phttpget_=: ,:'SoapAction';'http://schemas.microsoft.com/clr/nsassem/JDLLServerLib.JDLLServerClass/JDLLServerLib#DoR'
  q=. soapBody rplc '%1';y
  r=. q httpget'http://localhost/JApp/JDLLServer.3.soap'
  '<v [^>]+>([^<]+)</v>' (,.@{:@rxmatch ];.0 ]) r
)

regex is used to obtain the value of the result.

Here's how this verb is called:

   soapTest_phttpget_']a=: i.2 3'
0 1 2
3 4 5

   soapTest_phttpget_'+/ a'
3 5 7