服务端客户端都有的例子!麻烦了啊搞了一晚上都没有搞好啊!
麻烦大家乐。谢谢啊!

解决方案 »

  1.   


    谢谢啊!但是没有人回复
    google baidu上也没什么实质的内容啊!
      

  2.   


    谢谢啊!但是没有人回复
    google baidu上也没什么实质的内容啊!
      

  3.   


    谢谢啊!但是没有人回复
    google baidu上也没什么实质的内容啊!
      

  4.   

    public class GiftService
    {
        Map getGiftList() {       /* returns a map of NiceChild => Present */     }
    }
    <mappings>
      <mapping>
        <method name="getGiftList">
          <return-type keyType="org.codehaus.xfire.NiceChild" componentType="org.codehaus.xfire.Present">
        </method>
      </mapping>
    </mappings>
      

  5.   

    其实我觉得先把map转为json格式的,然后用string作为返回值就很好啊。这样有助于简化难度。
    用json-lib,或者gson。就行。string总是可以被多种WebService引擎所接受的。
      

  6.   

    可以,但很麻烦,需要使用 JAXB 的 XmlAdapter 进行转换,楼主去搜一下这个类,基本上就能找到怎么转了。
      

  7.   

    或者你看一下 XmlAdapter 的 API DOC 也行
    http://doc.java.sun.com/DocWeb/#r/Java%20EE%205/javax.xml.bind.annotation.adapters.XmlAdapter/columnMain
      

  8.   

    大火龙那
    public class GiftService 

        Map getGiftList() {       /* returns a map of NiceChild => Present */     } 

    <mappings> 
      <mapping> 
        <method name="getGiftList"> 
          <return-type keyType="org.codehaus.xfire.NiceChild" componentType="org.codehaus.xfire.Present"> 
        </method> 
      </mapping> 
    </mappings>这个说的是否对呢?
    直接用
    xfire生成?
      

  9.   

    webservice的server端应该在一台服务器上,
    client应该在另外一台服务器上
    我用xfire,在一个工程里同时生成server 和client可以运行。但是我吧client  copy到ejb的工程里。由于这个client里面用到了server端的属性  service0 = asf.create((com.webservice.PortType.class), props);其中com.webservice.PortType就server端的属性,这里一般都怎么做啊。吧server端内容打成jar包也复制到client端?
    其中  service0 = asf.create((com.webservice.PortType.class), props);是xfire自动生成的客户端啊啊。
      

  10.   

    webservice的server端应该在一台服务器上,
    client应该在另外一台服务器上
    我用xfire,在一个工程里同时生成server 和client可以运行。但是我吧client  copy到ejb的工程里。由于这个client里面用到了server端的属性  service0 = asf.create((com.webservice.PortType.class), props);其中com.webservice.PortType就server端的属性,这里一般都怎么做啊。吧server端内容打成jar包也复制到client端?
    其中  service0 = asf.create((com.webservice.topPortType.class), props);是xfire自动生成的客户端啊啊。
      

  11.   

    我在elps里面创建了一个web-service工程,然后用xfire创建客户端和服务端,
    然后发布到了tomcat里面。执行了也没有问题。然后我将客户端全部copy到我的ejb工程里然后吧xfire的依赖包 都导入ejb工程,同时把服务导出为一个.jar文件也导入了ejb工程并且放入了jboss的load目录。
    然后我启动了web-service服务端的tomcat
    然后启动了jboss跑的时候总是提示$Proxy539 cannot be cast to client.topPortType; CausedByException is: $Proxy539 cannot be cast to client.topPortType 其中topPortType 就是自动生成的客户端的类啊!
      

  12.   

    服务端:package com.webservice;public interface JieKou1 {
    public String getResult(String name,String old);
    }package com.webservice;public class ShiXian2 implements JieKou1{ public String getResult(String name, String old) {
    // TODO Auto-generated method stub
    return "Say Hello................";
    }

    }
    自动生成的客户端:package com.webservice;import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    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="in0" type="{http://www.w3.org/2001/XMLSchema}string"/>
     *         &lt;element name="in1" type="{http://www.w3.org/2001/XMLSchema}string"/>
     *       &lt;/sequence>
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "in0",
        "in1"
    })
    @XmlRootElement(name = "getResult")
    public class GetResult {    @XmlElement(required = true, nillable = true)
        protected String in0;
        @XmlElement(required = true, nillable = true)
        protected String in1;    /**
         * Gets the value of the in0 property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getIn0() {
            return in0;
        }    /**
         * Sets the value of the in0 property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setIn0(String value) {
            this.in0 = value;
        }    /**
         * Gets the value of the in1 property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getIn1() {
            return in1;
        }    /**
         * Sets the value of the in1 property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setIn1(String value) {
            this.in1 = value;
        }}package com.webservice;import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    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}string"/>
     *       &lt;/sequence>
     *     &lt;/restriction>
     *   &lt;/complexContent>
     * &lt;/complexType>
     * </pre>
     * 
     * 
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "out"
    })
    @XmlRootElement(name = "getResultResponse")
    public class GetResultResponse {    @XmlElement(required = true, nillable = true)
        protected String out;    /**
         * Gets the value of the out property.
         * 
         * @return
         *     possible object is
         *     {@link String }
         *     
         */
        public String getOut() {
            return out;
        }    /**
         * Sets the value of the out property.
         * 
         * @param value
         *     allowed object is
         *     {@link String }
         *     
         */
        public void setOut(String value) {
            this.out = value;
        }}package com.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.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.webservice
         * 
         */
        public ObjectFactory() {
        }    /**
         * Create an instance of {@link GetResult }
         * 
         */
        public GetResult createGetResult() {
            return new GetResult();
        }    /**
         * Create an instance of {@link GetResultResponse }
         * 
         */
        public GetResultResponse createGetResultResponse() {
            return new GetResultResponse();
        }}
    @javax.xml.bind.annotation.XmlSchema(namespace = "http://webservice.com", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    package com.webservice;package com.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 topClient {    private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
        private HashMap endpoints = new HashMap();
        private Service service0;    public topClient() {
            create0();
            Endpoint topPortTypeLocalEndpointEP = service0 .addEndpoint(new QName("http://webservice.com", "topPortTypeLocalEndpoint"), new QName("http://webservice.com", "topPortTypeLocalBinding"), "xfire.local://top");
            endpoints.put(new QName("http://webservice.com", "topPortTypeLocalEndpoint"), topPortTypeLocalEndpointEP);
            Endpoint topHttpPortEP = service0 .addEndpoint(new QName("http://webservice.com", "topHttpPort"), new QName("http://webservice.com", "topHttpBinding"), "http://127.0.0.1:8080/topwebservice/services/top");
            endpoints.put(new QName("http://webservice.com", "topHttpPort"), topHttpPortEP);
        }    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.webservice.topPortType.class), props);
            {
                AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://webservice.com", "topPortTypeLocalBinding"), "urn:xfire:transport:local");
            }
            {
                AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://webservice.com", "topHttpBinding"), "http://schemas.xmlsoap.org/soap/http");
            }
        }    public topPortType gettopPortTypeLocalEndpoint() {
            return ((topPortType)(this).getEndpoint(new QName("http://webservice.com", "topPortTypeLocalEndpoint")));
        }    public topPortType gettopPortTypeLocalEndpoint(String url) {
            topPortType var = gettopPortTypeLocalEndpoint();
            org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
            return var;
        }    public topPortType gettopHttpPort() {
            return ((topPortType)(this).getEndpoint(new QName("http://webservice.com", "topHttpPort")));
        }    public topPortType gettopHttpPort(String url) {
            topPortType var = gettopHttpPort();
            org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
            return var;
        }    public static void main(String[] args) {
                    topClient client = new topClient();
            
    //create a default service endpoint
            topPortType service = client.gettopHttpPort();
            
            System.out.println(service.getResult("",""));
    //TODO: Add custom client code here
             //
             //service.yourServiceOperationHere();
            
    System.out.println("test client completed");
             System.exit(0);
        }}
      

  13.   

    [code]
    package com.webservice;import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;@WebService(name = "topPortType", targetNamespace = "http://webservice.com")
    @SOAPBinding(use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
    public interface topPortType { @WebMethod(operationName = "getResult", action = "")
    @WebResult(name = "out", targetNamespace = "http://webservice.com")
    public String getResult(
    @WebParam(name = "in0", targetNamespace = "http://webservice.com")
    String in0,
    @WebParam(name = "in1", targetNamespace = "http://webservice.com")
    String in1);}[/code]xml文件<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://xfire.codehaus.org/config/1.0"> <service>
    <name>top</name>
    <serviceClass>com.webservice.JieKou1</serviceClass>
    <implementationClass>
    com.webservice.ShiXian2
    </implementationClass>
    <style>wrapped</style>
    <use>literal</use>
    <scope>application</scope>
    </service></beans>
      

  14.   

    ejb里面调用就直接
    topClient client = new topClient(); // create a default service endpoint
    topPortType service = client.gettopHttpPort();
    调用的啊
     TransactionRolledbackLocalException in method: 
    java.lang.ClassCastException: $Proxy539 cannot be cast to client.topPortType
    at client.topClient.gettopHttpPort(topClient.java:79)
    提示