简体   繁体   English

JAX-WS使用特定于实现的API(例如CXF)调用Web服务

[英]JAX-WS Invoking a webservice using Implementation specific API such as CXF

Is it possible to invoke a web service in Java without using the JAX-WS API but a specific runtime implementation API such as CXF specific API? 是否可以不使用JAX-WS API而是使用特定的运行时实现API(例如CXF特定的API)来调用Java中的Web服务?

I have Metro on my classpath an its causing issues when I use the JAX-WS API so I want to specify the exact JAX-WS API implementation to use dynamically when invoking the service 我在类路径上使用Metro时,在使用JAX-WS API时会引起问题,因此我想指定确切的JAX-WS API实施,以在调用服务时动态使用

Thank u 感谢你

You may build your request in plain XML and do SOAP request. 您可以使用纯XML构建请求并执行SOAP请求。 To build XML structure, you may use SoapUI, where you can import WSDL which gives you xml input structure. 要构建XML结构,您可以使用SoapUI,在其中可以导入W​​SDL,从而为您提供xml输入结构。 Copy that in to java class,append the request params where ever necessary and fire the request. 将其复制到java类中,在必要时附加请求参数并触发请求。 You don't require any Jax-WS API. 您不需要任何Jax-WS API。 Only the problem with this aproach is you need to write XML parser for inputs and outputs 唯一的问题是您需要为输入和输出编写XML解析器

[update] different solution [更新]不同的解决方案

I use Java API to use framework features, but need to create client jars for given service and add to class path. 我使用Java API来使用框架功能,但需要为给定的服务创建客户端jar并添加到类路径。

URL wsdlURL = new URL("http://localhost/myweb/services/xyz_services?wsdl");
        QName SERVICE_NAME = new QName("http://service.sa.com/","portname");
        Service service = Service.create(wsdlURL, SERVICE_NAME);

        TestService client = service.getPort(TestService.class);
        client.execute();

Provided your service looks like below 提供的服务如下所示

package com.sa.service;
        Inteface TestService{
            public void execute();
        }

You can create client class using wsimport (Java tool) from command line and then jar them and add to classpath 您可以从命令行使用wsimport (Java工具)创建客户端类,然后对其进行jar并添加到classpath

Most likely, all the JAX-WS implementations have some sort of proprietary API that can be used to create services that would use their specific implementation and bypass the JAX-WS provider discovery mechanisms. 最可能的是,所有JAX-WS实现都有某种专有的API,可用于创建使用其特定实现并绕过JAX-WS提供程序发现机制的服务。 In most cases, the discovered Providers are likely a wrapper onto those API's. 在大多数情况下,发现的提供程序可能是这些API的包装。

For CXF on the client side, that would be the JaxWsProxyFactoryBean: 对于客户端上的CXF,应该是JaxWsProxyFactoryBean:

http://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.html http://cxf.apache.org/javadoc/latest/org/apache/cxf/jaxws/JaxWsProxyFactoryBean.html

which can be used to create the Proxy objects from the JAX-WS generated interfaces. 可以用来从JAX-WS生成的接口创建Proxy对象。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM