< web-app xmlns ="http://java.sun.com/xml/ns/javaee" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" version ="2.5" xsi:schemaLocation ="http://java.sun.com/xml/ns/javaee [url]http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd[/url]" >
< servlet >
< servlet-name >XFireServlet </ servlet-name >
< servlet-class >org.codehaus.xfire.transport.http.XFireConfigurableServlet </ servlet-class >
< load-on-startup >0 </ load-on-startup >
</ servlet >
< servlet-mapping >
< servlet-name >XFireServlet </ servlet-name >
< url-pattern >/services/* </ url-pattern >
</ servlet-mapping >
< welcome-file-list >
< welcome-file >index.jsp </ welcome-file >
</ welcome-file-list >
</web-app>
< beans xmlns ="http://xfire.codehaus.org/config/1.0" >
< service >
< name >MyService </ name >
< serviceClass >wstest.server.IMyService </ serviceClass >
< implementationClass >
wstest.server.MyServiceImpl
</ implementationClass >
< style >wrapped </ style >
< use >literal </ use >
< scope >application </ scope >
</ service >
</beans>
//Generated by MyEclipse
public interface IMyService {
public String sayHello(String user);
}
//Generated by MyEclipse
public class MyServiceImpl implements IMyService {
public String sayHello(String user) {
return "您好,"+user;
}
}
package wstest.client;
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 MyServiceClient {
private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
private HashMap endpoints = new HashMap();
private Service service0;
public MyServiceClient() {
create0();
Endpoint MyServicePortTypeLocalEndpointEP = service0 .addEndpoint( new QName( "http://server.wstest", "MyServicePortTypeLocalEndpoint"), new QName("http://server.wstest", "MyServicePortTypeLocalBinding"), "xfire.local://MyService");
endpoints.put(new QName("http://server.wstest", "MyServicePortTypeLocalEndpoint"), MyServicePortTypeLocalEndpointEP);
Endpoint MyServiceHttpPortEP = service0 .addEndpoint(new QName("http://server.wstest", "MyServiceHttpPort"), new QName("http://server.wstest", "MyServiceHttpBinding"), "http://localhost:8080/xfire126Demo/services/MyService");
endpoints.put(new QName("http://server.wstest", "MyServiceHttpPort"), MyServiceHttpPortEP);
}
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((wstest.client.MyServicePortType.class), props);
{
AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://server.wstest", "MyServiceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");
}
{
AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://server.wstest", "MyServicePortTypeLocalBinding"), "urn:xfire:transport:local");
}
}
public MyServicePortType getMyServicePortTypeLocalEndpoint() {
return ((MyServicePortType)(this).getEndpoint(new QName("http://server.wstest", "MyServicePortTypeLocalEndpoint")));
}
public MyServicePortType getMyServicePortTypeLocalEndpoint(String url) {
MyServicePortType var = getMyServicePortTypeLocalEndpoint();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
return var;
}
public MyServicePortType getMyServiceHttpPort() {
return ((MyServicePortType)(this).getEndpoint(new QName("http://server.wstest", "MyServiceHttpPort")));
}
public MyServicePortType getMyServiceHttpPort(String url) {
MyServicePortType var = getMyServiceHttpPort();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
return var;
}
public static void main(String[] args) {
MyServiceClient client = new MyServiceClient();
//create a default service endpoint
MyServicePortType service = client.getMyServiceHttpPort();
//TODO: Add custom client code here
//
//service.yourServiceOperationHere();
System.out.println("test client completed");
System.exit(0);
}
}
//
//service.yourServiceOperationHere();
//
//service.yourServiceOperationHere();
String helloString = service.sayHello( "熔岩");
System.out.println(helloString);
test client completed
本文出自 “熔 岩” 博客,转载请与作者联系!