1
votes

I'm trying, and failing, to get a very simple Web Service call via HTTP Adapter working. I must be missing something very simple.

I want to use this sample service:

http://www.webservicex.net/geoipservice.asmx I use Worklight's "Discover Backend Services" tool on the WSDL of the above service to generate the HTTP Adapter code. I deploy the adapter, then right-click - Run As - Invoke Worklight Procedure. In the Parameters area, I enter (with quotes):

"173.194.34.178"

Initially, I get an error about not having SOAPAction in the HTTP header, so I make an edit to the Adapter -impl.js to add the SOAPAction in manually:

function invokeWebService(body, headers){

    var soapActionHeader = '"http://www.webservicex.net/GetGeoIP"';

    var input = {
        method : 'post',
        returnedContentType : 'xml',
        path : '/geoipservice.asmx',
        headers : {'soapAction' : soapActionHeader},
        body: {
            content : body.toString(),
            contentType : 'text/xml; charset=utf-8'
        }
    };

    //Adding custom HTTP headers if they were provided as parameter to the procedure call 
    headers && (input['headers'] = headers);

    return WL.Server.invokeHttp(input);
}

This sorts the SOAPAction problem out, but using Invoke Worklight Procedure again results in:

"faultstring": "System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.ArgumentNullException: Value cannot be null.\nParameter name: input\n at System.Text.RegularExpressions.Regex.IsMatch(String input)\n at WebserviceX.Service.Adapter.IPAdapter.CheckIP(String IP)\n at WebserviceX.Service.GeoIPService.GetGeoIP(String IPAddress)\n --- End of inner exception stack trace ---"

Almost like the IP address isn't actually ending up in the outbound message.

Am I entering the Parameters correctly in the Invoke Worklight Procedure dialog box? Here is a link to an image of the dialog:

https://picasaweb.google.com/lh/photo/t_BpwCVgPmiSpgKld5kMOtMTjNZETYmyPJy0liipFm0?feat=directlink

1
See if the response to your other question helps in this case too: stackoverflow.com/a/24530329/1276624yossile
Many thanks for this - it does help a lot in structuring the JSON. Can I ask something related to the Service Property dialog? When I used the Discover Back End Services tool, it generated the Adapter and gave it a generic name - SoapAdapter1. It also put the entry into the Services node. I renamed the Adapter to something more suitable, but the Service Property dialog still has the adapter name as SoapAdapter1. Not a bit issue, but every time I do a build it re-creates a new Adapter called SoapAdapter1 unless I delete the Service entry. Can I change this somewhere?Andy Smith
The ability to produce a unique name to the generated adapter is not currently available. From reading the edited question, it seems like this is resolved - would you mind writing your solution as an Answer to the question please?Idan Adar

1 Answers

2
votes

After following some of the advice found here and in my other thread, I started to look into the SOAP which is being generated. I stuffed the WSDL into soapUI, here is some SOAP which definitely works:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webservicex.net/">
   <soapenv:Header/>
   <soapenv:Body>
      <web:GetGeoIP>
         <web:IPAddress>173.194.34.178</web:IPAddress>
      </web:GetGeoIP>
   </soapenv:Body>
</soapenv:Envelope>

If I hack my HTTP Adapter to accept string parameters, and just string this soap together, it works. However, this means that I've removed all the JSON behaviour. So, I tried to use a JSON parameter structure to arrive at the same SOAP (via all the auto-generated worklight stuff in the adapter, like buildBody and jsonToXML):

var params = {
        "GetGeoIP" : {
            "IPAddress" : "173.194.34.178"                  
        },          
};

var headers = {
        "SOAPAction": "http://www.webservicex.net/GetGeoIP"
};

I added some logging to the adapter, and CRUCIALLY changed the namespace definitions:

soapEnvNS = 'http://www.w3.org/2003/05/soap-envelope';
var request = buildBody(params, 'xmlns="http://www.webservicex.net/"', soapEnvNS);

WL.Logger.debug(request);    

return invokeWebService(request, headers);

...and the soap it now generates looks like this:

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Body>
    <GetGeoIP xmlns="http://www.webservicex.net/">
      <IPAddress>173.194.34.178</IPAddress>
    </GetGeoIP>
  </soap:Body>
</soap:Envelope>

Which is good enough for the service, and I get a good response!