[英]Java - using SOAP with generated from WSDL classes
I have a WSDL
schema link. 我有一个
WSDL
模式链接。 With NetBeans I generated classes from this schema. 使用NetBeans,我从该架构生成了类。 But I can't understand, how to use it to send request to server?
但是我不明白,如何使用它向服务器发送请求? There is a
XXXImplService extends Service
class generated by NetBeans, should I use it? NetBeans生成了一个
XXXImplService extends Service
类,我应该使用它吗? How? 怎么样?
As I think, I need just to create objects (which match WSDL
methods and classes), set necessary properties and somehow transform this objects into a text of request, then send it with and get text response, which I can transform into classes. 我认为,我只需要创建对象(与
WSDL
方法和类匹配),设置必要的属性,然后以某种方式将该对象转换为请求文本,然后将其发送并获得文本响应,就可以将其转换为类。 Is this true? 这是真的?
of course you have to use the WSDL
, follow below steps for a complete client app for a Java web service (JAX-WS): 当然,您必须使用
WSDL
,对于Java Web服务(JAX-WS)的完整客户端应用程序,请按照以下步骤操作:
assuming you have a Web Service like this: 假设您具有这样的Web服务:
@WebService
public class Hello {
private String message = new String("Hello, ");
public void Hello() {}
@WebMethod
public String sayHello(String name) {
return message + name + ".";
}
}
Uses the javax.xml.ws.WebServiceRef
annotation to declare a reference to a web service. 使用
javax.xml.ws.WebServiceRef
批注声明对Web服务的引用。 @WebServiceRef
uses the wsdlLocation element to specify the URI of the deployed service's WSDL file: @WebServiceRef
使用wsdlLocation元素来指定已部署服务的WSDL文件的URI:
@WebServiceRef(wsdlLocation="http://localhost:8080/helloservice/hello?wsdl") static HelloService service;
Retrieves a proxy to the service, also known as a port, by invoking getHelloPort on the service. 通过在服务上调用getHelloPort来检索该服务的代理(也称为端口)。
Hello port = service.getHelloPort();
The port implements the SEI defined by the service. 端口实现服务定义的SEI。
Invokes the port's sayHello method, passing to the service a name. 调用端口的sayHello方法,并将名称传递给服务。
String response = port.sayHello(name);
EDIT: (request in comments) if the web service request for basic authentication and want to pass a username and password you can pass them like this (there are other ways also): 编辑:(注释中的请求)如果Web服务请求基本身份验证并想要传递用户名和密码,您可以像这样传递它们(还有其他方法):
import java.net.Authenticator;
import java.net.PasswordAuthentication;
Authenticator authenticator = new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("usr", "pass".toCharArray());
}
};
Authenticator.setDefault(authenticator );
however if you want authentication in application level not on basic HTTP this link can be useful.
但是,如果要在应用程序级别而不是在基本HTTP上进行身份验证,则此链接可能会很有用。
You have to implement your code in this generated service impl and web method now. 您现在必须在此生成的服务impl和Web方法中实现代码。 So when you will be calling the service end point and a specific method, through a web service client ( SOAP UI etc), these generated classes will take the call and route through service impl, to your implementation.
因此,当您将通过Web服务客户端(SOAP UI等)调用服务端点和特定方法时,这些生成的类将采用调用并将其通过Service Impl路由至实现。
This tutorial will help you to do it step by step. 本教程将帮助您逐步进行操作。 Since you have already created stub classes, skip the first part.
由于您已经创建了存根类,因此请跳过第一部分。 Focus on "Web service invocation" section.
重点关注“ Web服务调用”部分。
http://www.ibm.com/developerworks/webservices/library/ws-apacheaxis/index.html?ca=dat http://www.ibm.com/developerworks/webservices/library/ws-apacheaxis/index.html?ca=dat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.