各位大虾,谁有java webservice的经典例子请发来参考参考!!!小弟在这里谢过。

解决方案 »

  1.   

    package com.east.webservice;import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    /**
     * <p>Java class for anonymous complex type.
     * 
     * <p>The following schema fragment specifies the expected content contained within this class.
     * 
     * <pre>
     * &lt;complexType>
     *   &lt;complexContent>
     *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
     *       &lt;sequence>
     *         &lt;element name="out" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
     *       &lt;/sequence>
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "out"
    })
    @XmlRootElement(name = "saveResponse")
    public class SaveResponse {    protected boolean out;    /**
         * Gets the value of the out property.
         * 
         */
        public boolean isOut() {
            return out;
        }    /**
         * Sets the value of the out property.
         * 
         */
        public void setOut(boolean value) {
            this.out = value;
        }}
    package com.east.webservice;import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;@WebService(name = "BankServicePortType", targetNamespace = "http://webservice.east.com")
    @SOAPBinding(use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
    public interface BankServicePortType { @WebMethod(operationName = "save", action = "")
    @WebResult(name = "out", targetNamespace = "http://webservice.east.com")
    public boolean save(
    @WebParam(name = "inId", targetNamespace = "http://webservice.east.com")
    String inId,
    @WebParam(name = "money", targetNamespace = "http://webservice.east.com")
    float money);}
    package com.east.webservice;import javax.xml.bind.annotation.XmlRegistry;
    /**
     * This object contains factory methods for each 
     * Java content interface and Java element interface 
     * generated in the com.east.webservice package. 
     * <p>An ObjectFactory allows you to programatically 
     * construct new instances of the Java representation 
     * for XML content. The Java representation of XML 
     * content can consist of schema derived interfaces 
     * and classes representing the binding of schema 
     * type definitions, element declarations and model 
     * groups.  Factory methods for each of these are 
     * provided in this class.
     * 
     */
    @XmlRegistry
    public class ObjectFactory {
        /**
         * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.east.webservice
         * 
         */
        public ObjectFactory() {
        }    /**
         * Create an instance of {@link SaveResponse }
         * 
         */
        public SaveResponse createSaveResponse() {
            return new SaveResponse();
        }    /**
         * Create an instance of {@link Save }
         * 
         */
        public Save createSave() {
            return new Save();
        }}package com.east.webservice;import java.net.MalformedURLException;
    import java.util.Collection;
    import java.util.HashMap;
    import javax.xml.namespace.QName;
    import org.codehaus.xfire.XFireRuntimeException;
    import org.codehaus.xfire.aegis.AegisBindingProvider;
    import org.codehaus.xfire.annotations.AnnotationServiceFactory;
    import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
    import org.codehaus.xfire.client.XFireProxyFactory;
    import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
    import org.codehaus.xfire.service.Endpoint;
    import org.codehaus.xfire.service.Service;
    import org.codehaus.xfire.soap.AbstractSoapBinding;
    import org.codehaus.xfire.transport.TransportManager;public class BankServiceClient {    private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
        private HashMap endpoints = new HashMap();
        private Service service0;    public BankServiceClient() {
            create0();
            Endpoint BankServiceHttpPortEP = service0 .addEndpoint(new QName("http://webservice.east.com", "BankServiceHttpPort"), new QName("http://webservice.east.com", "BankServiceHttpBinding"), "http://192.168.11.2:8080/WebServiceS/services/BankService");
            endpoints.put(new QName("http://webservice.east.com", "BankServiceHttpPort"), BankServiceHttpPortEP);
            Endpoint BankServicePortTypeLocalEndpointEP = service0 .addEndpoint(new QName("http://webservice.east.com", "BankServicePortTypeLocalEndpoint"), new QName("http://webservice.east.com", "BankServicePortTypeLocalBinding"), "xfire.local://BankService");
            endpoints.put(new QName("http://webservice.east.com", "BankServicePortTypeLocalEndpoint"), BankServicePortTypeLocalEndpointEP);
        }    public Object getEndpoint(Endpoint endpoint) {
            try {
                return proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());
            } catch (MalformedURLException e) {
                throw new XFireRuntimeException("Invalid URL", e);
            }
        }    public Object getEndpoint(QName name) {
            Endpoint endpoint = ((Endpoint) endpoints.get((name)));
            if ((endpoint) == null) {
                throw new IllegalStateException("No such endpoint!");
            }
            return getEndpoint((endpoint));
        }    public Collection getEndpoints() {
            return endpoints.values();
        }    private void create0() {
            TransportManager tm = (org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());
            HashMap props = new HashMap();
            props.put("annotations.allow.interface", true);
            AnnotationServiceFactory asf = new AnnotationServiceFactory(new Jsr181WebAnnotations(), tm, new AegisBindingProvider(new JaxbTypeRegistry()));
            asf.setBindingCreationEnabled(false);
            service0 = asf.create((com.east.webservice.BankServicePortType.class), props);
            {
                AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://webservice.east.com", "BankServicePortTypeLocalBinding"), "urn:xfire:transport:local");
            }
            {
                AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://webservice.east.com", "BankServiceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");
            }
        }    public BankServicePortType getBankServiceHttpPort() {
            return ((BankServicePortType)(this).getEndpoint(new QName("http://webservice.east.com", "BankServiceHttpPort")));
        }    public BankServicePortType getBankServiceHttpPort(String url) {
            BankServicePortType var = getBankServiceHttpPort();
            org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
            return var;
        }    public BankServicePortType getBankServicePortTypeLocalEndpoint() {
            return ((BankServicePortType)(this).getEndpoint(new QName("http://webservice.east.com", "BankServicePortTypeLocalEndpoint")));
        }    public BankServicePortType getBankServicePortTypeLocalEndpoint(String url) {
            BankServicePortType var = getBankServicePortTypeLocalEndpoint();
            org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
            return var;
        }    public static void main(String[] args) {
                    BankServiceClient client = new BankServiceClient();
            
    //create a default service endpoint
            BankServicePortType service = client.getBankServiceHttpPort();
            service.save("张栋芳", 10000000);
    //TODO: Add custom client code here
             //
             //service.yourServiceOperationHere();
            
    System.out.println("test client completed");
             System.exit(0);
        }}
      

  2.   

    我有apache cxf的web方式的列子,需要联系我