简体   繁体   中英

How to received SOAP XML on Java Web-Service

I have WSDL XML file, that is send by Client. It's for Notification Service. Means our client send SOAP notification to our server on URL http://xxx.xxx.com/notification .

I am new on SOAP Web service, I am unable to identify, How to get SOAP XML on JAVA web service.

Let me know if you need more clarification on it.

I am not clear what your requirement is. Is it to produce a wsdl so that the client can use it to call your services or you need to use the wsdl given to you to consume the third party services.

Assuming you have a wsdl and you want to call the services using the wsdl, below is what I propose.

You could do the eclipse way of generating the classes, the only downside to do that would be that you have to do that every time there is a change in the wsdl file.

If you are using a build tool like maven or gradle or ant then you can automate the "generation" process every time you build the project.

For example if you are using Maven you could add the jaxws-maven-plugin to achieve that as shown below. Add the following to the maven pom.xml file

The below xml is taken from https://github.com/mojohaus/jaxws-maven-plugin/blob/master/src/it/jaxws-ri-samples/fromwsdl/client/pom.xml

<build>
    <sourceDirectory>../src</sourceDirectory>
    <finalName>jaxws-fromwsdl-client</finalName>

    <plugins>

      <!-- generate web services classes from wsdl file --> 
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxws-maven-plugin</artifactId>
        <version>1.11</version>
        <executions>
          <execution>
            <goals>
              <goal>wsimport</goal>
            </goals>
            <configuration>
              <verbose>true</verbose>
              <wsdlUrls>
                <wsdlUrl>http://localhost:8080/jaxws-fromwsdl/addnumbers?wsdl</wsdlUrl>
              </wsdlUrls>
              <packageName>fromwsdl.client</packageName>
            </configuration>
          </execution>
        </executions>
      </plugin>


      <!-- configure compiler plugin to pickup only server side java files -->
      <!--   note that at compile phase, wsdl's classes are already generated -->
      <plugin>
       <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
          <includes>
            <include>*/client/*.java</include>
          </includes>
        </configuration>
      </plugin>

    </plugins>
  </build>

If you now what you expect to receive you could write the receiver class and if you use Eclipse:

In the Eclipse main menu, click on File > New > Other.

In the Wizard dialog, expand the Web Services node, select Web Service and click on Next.

On the Web Services wizard screen, select Bottom up Java bean Web Service for the web service type and use the Browse button to select the service implementation class.

The next screen lists the name of the WSDL file that will be created and the public methods available in the service implementation class that can be exposed through the SOAP web service.

Click on Next to continue. The Eclipse IDE will now generate the web service files.

You can then crate the client code from the WSDL, this is very generic but can be a starting point.

From your question it seems that you have one WSDL file and you want to hit webservice exposed by it . A quick way to get going is to :

1) Go to command prompt and do a wsimport on .wsdl file as -keep ( to save .java file generated from command ) .
2) Move generated java files in your workspace.
3) Look for service name and port name in .wsdl file and make objects of them subsequently .
4) And then go for operation in .wsdl as desired .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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