简体   繁体   English

带有wsdl文件的Java SOAP

[英]Java SOAP with wsdl file

Have anybody any examples how to realize simple SOAP service having only .wsdl file? 有没有人举例如何实现仅具有.wsdl文件的简单 SOAP服务? I have .wsdl file and I should send a request to the server and get some reply. 我有.wsdl文件,我应该向服务器发送请求并得到一些答复。 The solutions which I've found do not use wsdl files (for example Working Soap client example ). 我发现的解决方案不使用wsdl文件(例如Working Soap客户示例 )。 My wsdl file is quite big so I can't use it like a string in a console so I need some simple example that I will be able to modify :) I'm using java 8 with maven. 我的wsdl文件很大,因此我不能在控制台中像字符串一样使用它,因此我需要一些简单的示例,以便我进行修改:)我正在将Java 8与maven一起使用。 Thanks! 谢谢!

In my company, we are dealing a lot with SOAP requests to SAP. 在我的公司中,我们正在处理对SAP的SOAP请求。

We are using cxf-codegen-plugin for Maven. 我们正在为Maven使用cxf-codegen-plugin It generates from wsdl files SOAP structure as java classes (requests/responses/datatypes), which then can be used as a way of generating the request / response. 它从wsdl文件生成SOAP结构作为Java类(请求/响应/数据类型),然后可以将其用作生成请求/响应的方式。

Example setup of it in the pom.xml could look like this: 在pom.xml中的示例设置如下所示:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                         <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Wsdl files should be placed under src/main/resources/wsdl/ directory. Wsdl文件应放在src / main / resources / wsdl /目录下。

In the generated classes one of the class will be the destination service, which usually can be found in the node in the WSDL file (in most cases, it is at the bottom of the file). 在生成的类中,该类之一将是目标服务,通常可以在WSDL文件的节点中找到它(在大多数情况下,它位于文件的底部)。 Once the client is correctly instantiated, you should be able to send via it all POJO requests and retrieve the responses. 正确实例化客户端后,您应该能够通过它发送所有POJO请求并检索响应。

You need at least the objects and some configuration of your SOAP Framework. 您至少需要SOAP框架的对象和一些配置。 Ie with Apache Axis 2 you have to create your classes and your service class with a configuration of the object mapping. 即,使用Apache Axis 2,您必须使用对象映射的配置来创建您的类和服务类。

If you use Spring Framework, have a look at the Getting Started Project -> https://spring.io/guides/gs/producing-web-service/ 如果您使用Spring Framework,请查看“入门项目”-> https://spring.io/guides/gs/production-web-service/

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

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