【问题标题】:Migrating a CXF client that uses "simple frontend" to JAX-WS将使用“简单前端”的 CXF 客户端迁移到 JAX-WS
【发布时间】:2016-04-07 03:35:42
【问题描述】:

我有一个使用 Apache CXF 编写的 Web 服务客户端,它使用 simple frontend 样式。它可以动态调用远程 Web 服务上的方法,给定它的位置和服务实现的接口。

public static void callWsMethod(Class<?> serviceInterface, String address, String methodName,...) {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setServiceClass(serviceInterface);
    factory.setAddress(address);
    Object instance = factory.create();
    ... /*invoke method "methodName" on instance */

我想将此代码迁移到纯 JAX-WS 实现。我的代码应该类似于:

public static void callWsMethod(Class<?> serviceInterface, String address, String methodName,...) {
    URL wsdlLocation = new URL(address + "?wsdl");
    QName serviceName = new QName( .... , ....); //??? what goes here
    Service service = Service.create(wsdlLocation, serviceName);
    Object instance = service.getPort(serviceInterface);
    ... /*invoke method "methodName" on instance */

我怀疑这是可能的,因为上面引用的 CXF 文档说:

在“简单”情况下,Simple 前端发生的事情与 JAX-WS 中几乎相同。

我的第一个问题是QName 构造函数:

QName(java.lang.String namespaceURI, java.lang.String localPart) 

CXF 如何找出正确的namespaceURIlocalPart 来调用ws?

【问题讨论】:

标签: web-services cxf jax-ws cxf-client


【解决方案1】:

您有 WSDL 吗?

namespaceUri = /wsdl:definitions/@targetNamespace
localPort = /wsdl:definitions/wsdl:service/@name

如果您有 WSDL。为什么不简单地使用 wsimport 生成 SEI 类?您会看到生成的自动包含正确的 QName。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    相关资源
    最近更新 更多