Question

I am using Grails 2.2.3. I am not able to call a SOAP based JAVA web service with parameters from Grails. I am using wslite. We are able to call a SOAP based web service but when we are passing the parameter, at the server end always receiving as NULL.

My Groovy Code snippet is as follows:

package poc.service
@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.8.0')
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import wslite.soap.SOAPClient
import wslite.http.HTTPRequest
import wslite.http.HTTPResponse

class LoginService {
    static def checkUserData(def _userName12) {

       def client = new SOAPClient('http://192.168.14.147:9090/SOAPServiceDemo/authenticate')
        def userNameValue = _userName12   

        def response = client.send(SOAPAction:'\"http://example.service.com/checkUser\"'){
            header{
            }
            body {
                 checkUser(xmlns:'http://example.service.com/') { 
                     userName12(_userName12)
                 }
            }
        }
        println "User Name = " + response.checkUserResponse.return
    }

    static main(args){
       def status =  checkUserData('123') 
       println status
    }
}


Below is another example which is working fine. It is copied from google.

package poc.service

import wslite.soap.SOAPClient
import wslite.http.HTTPRequest
import wslite.http.HTTPResponse

class MothersDay {
    static def checkMotherData(String _userName12) {

       def client = new SOAPClient('http://www.holidaywebservice.com/Holidays/US/Dates/USHolidayDates.asmx')
       def response = client.send(SOAPAction:'http://www.27seconds.com/Holidays/US/Dates/GetMothersDay') {
           body {
               GetMothersDay('xmlns':'http://www.27seconds.com/Holidays/US/Dates/') {
                   year(_userName12)
               }
           }
       }
       println "Result = " + response.GetMothersDayResponse.GetMothersDayResult.toString()
    }

    static main(args){
       def status =  checkMotherData("2018")
    }
}

Please let me know if you have any idea where I am lacking.

Thanks
Ravi

No correct solution

OTHER TIPS

Use SOAPAction as

client.send(SOAPAction:'http://example.service.com/checkUser')

without trying to escape " which should not be part of the url.

This may be a little late for you, but for anyone else who had this problem it seems to be around how WSLite is setting the namespace for the method call. You can see the actual soap message that gets passed in by looking at how the SOAPClient generates the envelope using the SOAPMessageBuilder object (OpenSource is your friend). Anyway, to cut to the point, you need to add your namespace as part of the envelope attributes and then manually force your method to use that namespace instead of passing it is an argument to your method (which seems to only work for .NET web services). So it should look like this:

def response = client.send(SOAPAction:'http://example.service.com/checkUser') {         
    envelopeAttributes "xmlns:ex":"http://example.service.com/"
    body {
         'ex:checkUser'() { 
             userName12(_userName12)
         }
    }
}

Hope that helps for anyone else with this problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top