如何通过javax.xml.ws.Service进行调用 [英] How to do a call through a javax.xml.ws.Service

查看:2073
本文介绍了如何通过javax.xml.ws.Service进行调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中创建了一个新的标准java 7项目,并成功设法获取 javax.xml.ws.Service 的实例,如下所示:

Created a new standard java 7 project in Eclipse and have successfully managed to get an instance of a javax.xml.ws.Service like so:

  String wsdlURL = "http://example.com:3000/v1_0/foo/bar/SomeService?wsdl";
  String namespace = "http://foo.bar.com/webservice";
  String serviceName = "SomeService";
  QName serviceQN = new QName(namespace, serviceName);

  Service service = Service.create(new URL(wsdlURL), serviceQN);

这在主方法中运行良好,所以据我所知,该部分有效。但我无法弄清楚如何实际使用它。在SoapUI中,我使用如下所示的请求调用此相同服务:

This runs fine in a main method, so as far as I can see, that part works. But I can't figure out how to actually use it. In SoapUI I call this same service with a request which looks like the following:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://foo.bar.com/webservice">
   <soapenv:Header/>
   <soapenv:Body>
      <web:SomeWebServiceRequest acAccountName="name" acAccountPassword="password">
         <SomeRequest>
            <id>012345678901234</id>
            <action>Fix</action>
         </SomeRequest>
      </web:SomeWebServiceRequest>
   </soapenv:Body>
</soapenv:Envelope>

如何在Java中执行相同的请求?我的目标是我有一个很长的列表,这些 id ,我需要为它们中的每一个运行这样的请求。在SoapUI中手动执行它有点烦人,因此我想使用简单的Java控制台应用程序自动执行它。

How can I do the same request in Java? My goal is that I have a long list of these ids, and I need to run a request like that for each of them. Doing it manually in SoapUI is a bit annoying, so I'd like to automate it with a simple Java console application.

推荐答案

下一步是从您的服务获得端口

Next step is to get Port from your service:

Service service = Service.create(new URL(wsdlURL), serviceQN); // this is where you are.
QName portQName = new QName(portNamespace, portName);
YourPortInterface port = service.getPort(portQName, YourPortInterface.class);

YourPortInteface 将在<$ c期间生成$ c> wsimport 或者如果你有足够的阅读wsdl经验,你可以自己创建和注释。

YourPortInteface will be generated during wsimport or you can create and annotate it by yourself if you have enough experience in "reading" wsdl.

这篇关于如何通过javax.xml.ws.Service进行调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆