【问题标题】:Groovy wslite client not working for SOAP based java web serviceGroovy wslite 客户端不适用于基于 SOAP 的 Java Web 服务
【发布时间】:2014-04-05 02:14:34
【问题描述】:

我正在使用 Grails 2.2.3。 我无法使用 Grails 中的参数调用基于 SOAP 的 JAVA Web 服务。我正在使用wslite。我们可以调用基于 SOAP 的 Web 服务,但是当我们传递参数时,服务器端总是接收为 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

【问题讨论】:

    标签: grails groovy groovyws


    【解决方案1】:

    将 SOAPAction 用作

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

    不试图逃避不应成为网址一部分的"

    【讨论】:

      【解决方案2】:

      这对您来说可能有点晚了,但对于遇到此问题的其他人来说,这似乎与 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)
               }
          }
      }
      

      希望对解决此问题的其他人有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-08
        • 1970-01-01
        相关资源
        最近更新 更多