JAX-WS 之client应用客户端

1: 根据server段的wsdl 利用wsimport 工具生成客户端代码。

 

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<!--

 Published by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.2-b608 (trunk-7979; 2015-01-21T12:50:19+0000) JAXWS-RI/2.2.11-b150120.1832 JAXWS-API/2.2.12 JAXB-RI/2.2.12-b141219.1637 JAXB-API/2.2.13-b141020.1521 svn-revision#unknown. 

-->

<!--

 Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is Metro/2.3.2-b608 (trunk-7979; 2015-01-21T12:50:19+0000) JAXWS-RI/2.2.11-b150120.1832 JAXWS-API/2.2.12 JAXB-RI/2.2.12-b141219.1637 JAXB-API/2.2.13-b141020.1521 svn-revision#unknown. 

-->

<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://JAX_WS.webservice/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://JAX_WS.webservice/" name="HelloService">

<types>

<xsd:schema>

<xsd:import namespace="http://JAX_WS.webservice/" schemaLocation="http://cn00202245:8080/JAX-WS-1.0/HelloService?xsd=1"/>

</xsd:schema>

</types>

<message name="sayHello">

<part name="parameters" element="tns:sayHello"/>

</message>

<message name="sayHelloResponse">

<part name="parameters" element="tns:sayHelloResponse"/>

</message>

<portType name="Hello">

<operation name="sayHello">

<input wsam:Action="http://JAX_WS.webservice/Hello/sayHelloRequest" message="tns:sayHello"/>

<output wsam:Action="http://JAX_WS.webservice/Hello/sayHelloResponse" message="tns:sayHelloResponse"/>

</operation>

</portType>

<binding name="HelloPortBinding" type="tns:Hello">

<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>

<operation name="sayHello">

<soap:operation soapAction=""/>

<input>

<soap:body use="literal"/>

</input>

<output>

<soap:body use="literal"/>

</output>

</operation>

</binding>

<service name="HelloService">

<port name="HelloPort" binding="tns:HelloPortBinding">

<soap:address location="http://cn00202245:8080/JAX-WS-1.0/HelloService"/>

</port>

</service>

</definitions>

 

 

2:

"C:\\Program Files\\Java\\jdk1.7.0_51\\bin\\wsimport.exe" -keep -p client.JAX_WS http://localhost:8080/JAX-WS-1.0/HelloService?wsdl

 

 

 3.生成客户端代码

/**

 * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved.

 *

 * You may not modify, use, reproduce, or distribute this software except in

 * compliance with  the terms of the License at:

 * http://java.net/projects/javaeetutorial/pages/BerkeleyLicense

 */

package javaeetutorial.hello.webclient;

 

 

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.xml.ws.WebServiceRef;

 

import frank.Hello;

import frank.HelloService;

 

@WebServlet(name="HelloServlet", urlPatterns={"/HelloServlet"})

public class HelloServlet extends HttpServlet {

// wsimport  -p frank -s http://localhost:8080/helloservice-war/HelloService?WSDL

    @WebServiceRef(wsdlLocation = "http://localhost:8080/helloservice-war/HelloService?WSDL")

    private HelloService service;

   

    /** 

     * Processes requests for both HTTP <code>GET</code>

     *   and <code>POST</code> methods.

     * @param request servlet request

     * @param response servlet response

     * @throws ServletException if a servlet-specific error occurs

     * @throws IOException if an I/O error occurs

     */

    protected void processRequest(HttpServletRequest request,

            HttpServletResponse response)

    throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");

        try (PrintWriter out = response.getWriter()) {

            

            out.println("<html lang=\"en\">");

            out.println("<head>");

            out.println("<title>Servlet HelloServlet</title>");  

            out.println("</head>");

            out.println("<body>");

            out.println("<h1>Servlet HelloServlet at " + 

                request.getContextPath () + "</h1>");

            out.println("<p>" + sayHello("world") + "</p>");

            out.println("</body>");

            out.println("</html>");

            

        }

    } 

 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">

    /** 

     * Handles the HTTP <code>GET</code> method.

     * @param request servlet request

     * @param response servlet response

     * @throws ServletException if a servlet-specific error occurs

     * @throws IOException if an I/O error occurs

     */

    @Override

    protected void doGet(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

        processRequest(request, response);

    } 

 

    /** 

     * Handles the HTTP <code>POST</code> method.

     * @param request servlet request

     * @param response servlet response

     * @throws ServletException if a servlet-specific error occurs

     * @throws IOException if an I/O error occurs

     */

    @Override

    protected void doPost(HttpServletRequest request, HttpServletResponse response)

    throws ServletException, IOException {

        processRequest(request, response);

    }

 

    /** 

     * Returns a short description of the servlet.

     * @return a String containing servlet description

     */

    @Override

    public String getServletInfo() {

        return "Short description";

    }// </editor-fold>

 

    private String sayHello(java.lang.String arg0) {

        Hello port = 

                service.getHelloPort();

        return port.sayHello(arg0);

    }

}

 

 

 

你可能感兴趣的:(JAX-WS 之client应用客户端)