服务端客户端都有的例子!麻烦了啊搞了一晚上都没有搞好啊!
麻烦大家乐。谢谢啊!
麻烦大家乐。谢谢啊!
解决方案 »
- 急啊 都来看看 JAVA 如何调用DLL得到其inout 类型的参数
- 用swing怎么实现一个 计算器的功能?
- 文件读取的问题
- 如何查看一个class文件是由那个jdk版本编译的
- 关于java网络的一个不知道问题在哪儿的问题。
- 各位有沒有一本好的java e-book 介紹一下, 謝謝謝謝謝謝謝
- 高分求教,我把一个image对象打成了int[],但是我怎么把这个int[]再专成image呢!?
- 关于mouse right click的问题
- 常有人说java什么都能做,我作为一个初学者对此感到很困惑!
- java能做短信息发送软件吗?接口是什么?谁能明确说说这方面知识
- java 中定義byte類型數組,元素為16進制
- 关于java applet内存泄漏问题
谢谢啊!但是没有人回复
google baidu上也没什么实质的内容啊!
谢谢啊!但是没有人回复
google baidu上也没什么实质的内容啊!
谢谢啊!但是没有人回复
google baidu上也没什么实质的内容啊!
{
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>
用json-lib,或者gson。就行。string总是可以被多种WebService引擎所接受的。
http://doc.java.sun.com/DocWeb/#r/Java%20EE%205/javax.xml.bind.annotation.adapters.XmlAdapter/columnMain
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生成?
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自动生成的客户端啊啊。
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自动生成的客户端啊啊。
然后发布到了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 就是自动生成的客户端的类啊!
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>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="in0" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="in1" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </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>
* <complexType>
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="out" type="{http://www.w3.org/2001/XMLSchema}string"/>
* </sequence>
* </restriction>
* </complexContent>
* </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);
}}
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>
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)
提示