如何通过javax.xml.ws.Service进行呼叫
在Eclipse中创建了一个新的标准Java 7项目,并成功地成功获取了javax.xml.ws.Servicelike 的实例,如下所示:
  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中,我通过以下请求调用此服务:
<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控制台应用程序将其自动化。
回答:
下一步是Port从您的服务中获取帮助:
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将在期间生成,wsimport或者,如果您有足够的“阅读” wsdl经验,则可以自己创建和注释它。
以上是 如何通过javax.xml.ws.Service进行呼叫 的全部内容, 来源链接: utcz.com/qa/399825.html
