0

Have anybody any examples how to realize simple SOAP service having only .wsdl file? I have .wsdl file and I should send a request to the server and get some reply. The solutions which I've found do not use wsdl files (for example Working Soap client example). 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. Thanks!

Gwalk
  • 211
  • 4
  • 13

2 Answers2

1

In my company, we are dealing a lot with SOAP requests to SAP.

We are using cxf-codegen-plugin for Maven. 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.

Example setup of it in the pom.xml could look like this:

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

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). Once the client is correctly instantiated, you should be able to send via it all POJO requests and retrieve the responses.

Rafał Czabaj
  • 720
  • 7
  • 16
  • yep, you're right. There is some service that contains annotation WebServiceClient and it methods annotated with WebEndpoint. I should use this service to send requests. Right? – Gwalk Mar 26 '18 at 14:07
  • @Gwalk yes, normally if you have X number of services specified, they give you the ability to "talk" with the SOAP webservice. Give it a try, try the most simple ones to see if you can communicate with it. if you have any "dummy" endpoint, that would be good second test. – Rafał Czabaj Mar 26 '18 at 14:21
0

You need at least the objects and some configuration of your SOAP Framework. I.e. with Apache Axis 2 you have to create your classes and your service class with a configuration of the object mapping.

If you use Spring Framework, have a look at the Getting Started Project -> https://spring.io/guides/gs/producing-web-service/

Lord_Pinhead
  • 127
  • 1
  • 10
  • I don't use Spring. I've generated classes with java wsimport tool, but don't exactly know what to do next :) – Gwalk Mar 26 '18 at 11:41
  • So you already have your endpoint running and you can access the soap methods via soap ui as a test? After that, you need the soap clients, i use wsdl2java for that. – Lord_Pinhead Mar 26 '18 at 12:50