我在Grails项目中使用ws-client来调用Web服务。

可以,但是它是从WSDL读取端点。

如何在运行时更改端点?

def proxy = new WSClient(wsdlURL, Thread.currentThread().getContextClassLoader());
proxy.setEndpoint(''); // this doesn't exists, ERROR!

谢谢!

注意:是否需要使用BindingProvider.ENDPOINT_ADDRESS_PROPERTY解决此问题?

最佳答案

您可以通过执行以下代码来更改端点地址:

// getter method for the wrapped client class
WSClient.metaClass.getCxfClient = { ->
    delegate.client
}
// init ws client
proxy = new WSClient(wsdlURL, this.class.classLoader)
proxy.initialize()
// get client instance
def cxfClient = proxy.cxfClient
// create new endpoint url
URL newUrl = new URL("http://edu-02:8080/educenter/services/sync")
// assign new created url to the client
cxfClient.getConduit().getTarget().getAddress().setValue(newUrl.toExternalForm());

关于grails - Groovy:如何使用ws-client更改端点?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6820957/

10-11 04:02
查看更多