2009-09-08 49 views

回答

3

如果你正在使用Spring,你可以配置客户端(这是我在最近的一个项目完成)创建一个帮助豆:

<bean name="exampleClient" class="com.lingoswap.ws.util.JaxWsClientFactoryBean"> 
    <property name="wsdlDocumentLocation" value="${exampleClient.wsdlDocumentLocation}" /> 
    <property name="namespaceURI" value="http://com.example/exampleClient" /> 
    <property name="localPart" value="ExampleService" /> 
    <property name="serviceEndpointInterface" value="com.example.ExampleServicePortType" /> 
</bean> 

的$ {之间的部分... }是属性占位符,这意味着从PropertyPlaceholderConfigurer指定的属性文件中查找该值。指定值的示例如下所示:

## Web Service WSDL locations 
exampleClient.wsdlDocumentLocation=http://www.example.com/exampleService?wsdl 

然后,您可以修改属性文件(也许“myapplication.properties”)更改WSDL位置需要(即使在运行时,如果您使用自定义的TargetSource一个ProxyFactoryBean一样)对于它的价值,这是我实现一个简单的JaxWsClientFactoryBean(无自动属性修改支持):

package com.lingoswap.ws.util; 

import java.net.URL; 
import javax.xml.namespace.QName; 
import javax.xml.ws.Service; 
import org.springframework.beans.factory.FactoryBean; 
import org.springframework.beans.factory.InitializingBean; 

public class JaxWsClientFactoryBean implements FactoryBean, InitializingBean { 

    private URL wsdlDocumentLocation; 
    private Class<?> serviceEndpointInterface; 
    private String namespaceURI; 
    private String localPart; 

    // derived from namespaceURI and localPart 
    private QName serviceName; 

    public void afterPropertiesSet() {  
     serviceName = new QName(namespaceURI, localPart); 
    } 

    public Object getObject() { 
     Service service = Service.create(wsdlDocumentLocation, serviceName); 
     Object port = service.getPort(serviceEndpointInterface); 
     return port; 
    } 
    public Class<?> getObjectType() { 
     return serviceEndpointInterface; 
    } 
    public boolean isSingleton() { 
     return false; 
    } 
    public URL getWsdlDocumentLocation() { 
     return wsdlDocumentLocation; 
    } 
    public void setWsdlDocumentLocation(final URL wsdlDocumentLocation) { 
     this.wsdlDocumentLocation = wsdlDocumentLocation; 
    } 
    public Class<?> getServiceEndpointInterface() { 
     return serviceEndpointInterface; 
    } 
    public void setServiceEndpointInterface(
     final Class<?> serviceEndpointInterface) { 
     this.serviceEndpointInterface = serviceEndpointInterface; 
    } 
    public String getNamespaceURI() { 
     return namespaceURI; 
    } 
    public void setNamespaceURI(final String namespaceURI) { 
     this.namespaceURI = namespaceURI; 
    } 
    public String getLocalPart() { 
     return localPart; 
    } 
    public void setLocalPart(final String localPart) { 
     this.localPart = localPart; 
    } 
} 

我决定提供一个答案,即使你已经回答了你自己的问题。也许你会发现这个建议很有用。使用类似FactoryBean的实现的好处在于,它可以重用于所有Web服务客户端,并封装来自其消费者的Web服务创建。您的Web层或业务层对象将仅取决于SEI(服务端点接口)。

0

我得到了我的问题解决方案:

其实我是使用Web服务的默认构造函数用于创建服务实例。

我们可以使用已创建的存根,并将构造函数的新重定位WSDLURL作为参数,因此我们不需要再创建客户端存根。

更该给here:

感谢你。

0

创建存根的代码可以写成,

URL wsdlLocation = new URL("http://example.org/my.wsdl"); 
QName serviceName = new QName("http://example.org/sample", "MyService"); 
Service s = Service.create(wsdlLocation, serviceName); 

我们可以使用属性文件在运行时更改WSDL位置的目的。
甚至不需要编译客户端代码。

相关问题