非常详细的webservice部署测试程序
网站来源: http://lavasoft.blog.51cto.com/62575/105956/


<web-appxmlns="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>


<beansxmlns="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>//GeneratedbyMyEclipse
publicinterfaceIMyService{
publicStringsayHello(Stringuser);
}//GeneratedbyMyEclipse
publicclassMyServiceImplimplementsIMyService{
publicStringsayHello(Stringuser){
return"您好,"+user;
}
}







packagewstest.client;
importjava.net.MalformedURLException;
importjava.util.Collection;
importjava.util.HashMap;
importjavax.xml.namespace.QName;
importorg.codehaus.xfire.XFireRuntimeException;
importorg.codehaus.xfire.aegis.AegisBindingProvider;
importorg.codehaus.xfire.annotations.AnnotationServiceFactory;
importorg.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
importorg.codehaus.xfire.client.XFireProxyFactory;
importorg.codehaus.xfire.jaxb2.JaxbTypeRegistry;
importorg.codehaus.xfire.service.Endpoint;
importorg.codehaus.xfire.service.Service;
importorg.codehaus.xfire.soap.AbstractSoapBinding;
importorg.codehaus.xfire.transport.TransportManager;
publicclassMyServiceClient{
privatestaticXFireProxyFactoryproxyFactory=newXFireProxyFactory();
privateHashMapendpoints=newHashMap();
privateServiceservice0;
publicMyServiceClient(){
create0();
EndpointMyServicePortTypeLocalEndpointEP=service0.addEndpoint(newQName("http://server.wstest","MyServicePortTypeLocalEndpoint"),newQName("http://server.wstest","MyServicePortTypeLocalBinding"),"xfire.local://MyService");
endpoints.put(newQName("http://server.wstest","MyServicePortTypeLocalEndpoint"),MyServicePortTypeLocalEndpointEP);
EndpointMyServiceHttpPortEP=service0.addEndpoint(newQName("http://server.wstest","MyServiceHttpPort"),newQName("http://server.wstest","MyServiceHttpBinding"),"http://localhost:8080/xfire126Demo/services/MyService");
endpoints.put(newQName("http://server.wstest","MyServiceHttpPort"),MyServiceHttpPortEP);
}
publicObjectgetEndpoint(Endpointendpoint){
try{
returnproxyFactory.create((endpoint).getBinding(),(endpoint).getUrl());
}catch(MalformedURLExceptione){
thrownewXFireRuntimeException("InvalidURL",e);
}
}
publicObjectgetEndpoint(QNamename){
Endpointendpoint=((Endpoint)endpoints.get((name)));
if((endpoint)==null){
thrownewIllegalStateException("Nosuchendpoint!");
}
returngetEndpoint((endpoint));
}
publicCollectiongetEndpoints(){
returnendpoints.values();
}
privatevoidcreate0(){
TransportManagertm=(org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());
HashMapprops=newHashMap();
props.put("annotations.allow.interface",true);
AnnotationServiceFactoryasf=newAnnotationServiceFactory(newJsr181WebAnnotations(),tm,newAegisBindingProvider(newJaxbTypeRegistry()));
asf.setBindingCreationEnabled(false);
service0=asf.create((wstest.client.MyServicePortType.class),props);
{
AbstractSoapBindingsoapBinding=asf.createSoap11Binding(service0,newQName("http://server.wstest","MyServiceHttpBinding"),"http://schemas.xmlsoap.org/soap/http");
}
{
AbstractSoapBindingsoapBinding=asf.createSoap11Binding(service0,newQName("http://server.wstest","MyServicePortTypeLocalBinding"),"urn:xfire:transport:local");
}
}
publicMyServicePortTypegetMyServicePortTypeLocalEndpoint(){
return((MyServicePortType)(this).getEndpoint(newQName("http://server.wstest","MyServicePortTypeLocalEndpoint")));
}
publicMyServicePortTypegetMyServicePortTypeLocalEndpoint(Stringurl){
MyServicePortTypevar=getMyServicePortTypeLocalEndpoint();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
returnvar;
}
publicMyServicePortTypegetMyServiceHttpPort(){
return((MyServicePortType)(this).getEndpoint(newQName("http://server.wstest","MyServiceHttpPort")));
}
publicMyServicePortTypegetMyServiceHttpPort(Stringurl){
MyServicePortTypevar=getMyServiceHttpPort();
org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
returnvar;
}
publicstaticvoidmain(String[]args){
MyServiceClientclient=newMyServiceClient();
//createadefaultserviceendpoint
MyServicePortTypeservice=client.getMyServiceHttpPort();
//TODO:Addcustomclientcodehere
//
//service.yourServiceOperationHere();
System.out.println("testclientcompleted");
System.exit(0);
}
}
//
//service.yourServiceOperationHere();
//
//service.yourServiceOperationHere();
StringhelloString=service.sayHello("熔岩");
System.out.println(helloString);本文出自 “熔 岩” 博客,转载请与作者联系!