简体   繁体   English

Java-将SOAP与从WSDL类生成的结合使用

[英]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 + ".";
    }
}
  1. 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;

  2. 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。

  3. 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.

相关问题 Java类从wsdl生成SOAP请求 - Java classes to generate SOAP requests from wsdl 使用Axis java2wsdl / wsdl2java生成的源类不同于原始类 - Generated source classes using Axis java2wsdl / wsdl2java differs from original 如何将pfx文件转换为jks,然后通过使用wsdl生成的类将其用于签署传出的soap请求 - How to convert a pfx file into jks and then use it to sign an outgoing soap request by using the classes generated from a wsdl Generated sources from WSDL using WSDL2Java generates classes with deprecated API javax xml ws on java 11 - Generated sources from WSDL using WSDL2Java generates classes with deprecated API javax xml ws on java 11 Java 类不是使用 maven-jaxb2-plugin 从 wsdl 文件生成的 - Java classes are not generated from wsdl file using maven-jaxb2-plugin 使用wsdl禁用和启用自动生成的Java类的选项 - Option for disabling and enabling auto generated java classes using wsdl 修改从wsdl生成的java类的包名称 - Modify package names for java classes generated from wsdl 如何使用wsdl生成的java对象发出soap请求时添加soap标头 - How to add soap header when making a soap request using the java objects generated by wsdl Clickatell SOAP wsdl到JAXB Java类 - Clickatell SOAP wsdl to JAXB java classes 使用默认的Java 1.6 java.xml.ws API在生成的WSDL中缺少SOAP方法参数 - Missing SOAP method parameters in generated WSDL using the default Java 1.6 java.xml.ws API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM