2013-10-04 41 views
3

我正在使用Grails 2.2.3。 我无法使用Grails中的参数调用基于SOAP的JAVA Web服务。我正在使用wslite。我们可以调用基于SOAP的Web服务,但是当我们传递参数时,服务器端总是接收为NULL。Groovy wslite客户端不能用于基于SOAP的java web服务

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 

回答

2

使用的SOAPAction作为

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

没有试图逃跑"这不应该是URL的一部分。

1

对于你来说这可能有点晚,但对于有这个问题的其他人来说,它似乎是围绕着如何为WSLite设置方法调用的命名空间。通过查看SOAPClient如何使用SOAPMessageBuilder对象(OpenSource是您的朋友)生成信封,您可以看到传入的实际SOAP消息。无论如何,为了切入点,您需要将您的名称空间添加为信封属性的一部分,然后手动强制您的方法使用该名称空间而不是传递它,这是您的方法的一个参数(这似乎只适用于.NET Web服务)。所以它应该看起来像这样:

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

希望能帮助其他任何人解决这个问题。