|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
如果你学习的是市场营销,是销售,也许参加大课堂的学习会更合适,因为你的工作能力中有个基础就是搭建自己的人脉,webAxis撑持三种webservice的部署和开辟,分离为:
1、DynamicInvocationInterface(DII)
2、Stubs体例
3、DynamicProxy体例
2、编写DII(DynamicInvocationInterface)体例web服务
1.编写服务端程序HelloClient
publicclassHelloClient
{
publicStringgetName(Stringname)
{
return"hello"+name;
}
}
2、将源码拷贝到Axis_HOME下,重定名为HelloClient.jws
3、会见毗连http://localhost:8080/Axis/HelloClient.jws?wsdl,页面显现Axis主动天生的wsdl
4、编写会见服务的客户端TestHelloClient.java
importorg.apache.Axis.client.Call;
importorg.apache.Axis.client.Service;
importjavax.xml.namespace.QName;
importjavax.xml.rpc.ServiceException;
importjava.net.MalformedURLException;
importjava.rmi.RemoteException;
publicclassSayHelloClient2
{
publicstaticvoidmain(String[]args)
{
try
{
Stringendpoint=
"http://localhost:8080/Axis/HelloClient.jws";
Serviceservice=newService();
Callcall=null;
call=(Call)service.createCall();
call.setOperationName(newQName(
"http://localhost:8080/Axis/HelloClient.jws",
"getName"));
call.setTargetEndpointAddress
(newjava.net.URL(endpoint));
Stringret=(String)call.invoke(newObject[]
{"zhangsan"});
System.out.println("returnvalueis"+ret);
}
catch(Exceptionex)
{
ex.printStackTrace();
}
}
}
3、编写DynamicProxy体例会见服务
1、编写部署服务端程序,同上边DII体例,本次仍利用上边部署的HelloClient
2、编写代办署理接口
publicinterfaceHelloClientInterface
extendsjava.rmi.Remote
{
publicStringgetName(Stringname)
throwsjava.rmi.RemoteException;
}
3、编写并实行客户端程序TestHelloClient.java
importjavax.xml.rpc.Service;
importjavax.xml.rpc.ServiceFactory;
importjava.net.URL;
importjavax.xml.namespace.QName;
publicclassTestHelloClient
{
publicstaticvoidmain(String[]args)
{
try
{
StringwsdlUrl=
"http://localhost:8080/Axis/HelloClient.jws?wsdl";
StringnameSpaceUri=
"http://localhost:8080/Axis/HelloClient.jws";
StringserviceName="HelloClientService";
StringportName="HelloClient";
ServiceFactoryserviceFactory=
ServiceFactory.newInstance();
ServiceafService=
serviceFactory.createService(newURL(wsdlUrl),
newQName(nameSpaceUri,serviceName));
HelloClientInterfaceproxy=(HelloClientInterface)
afService.getPort(newQName(
nameSpaceUri,portName),
HelloClientInterface.class);
System.out.println
("returnvalueis"+proxy.getName("john"));
}catch(Exceptionex)
{
ex.printStackTrace();
}
}
}
4、编写wsdd公布web服务,编写stubclient会见web服务
1、编写服务端程序server,SayHello.java,编译server.SayHello.java
packageserver;
publicclassSayHello
{
publicStringgetName(Stringname)
{
return"hello"+name;
}
}
2.编写LogHandler.java
importorg.apache.Axis.AxisFault;
importorg.apache.Axis.Handler;
importorg.apache.Axis.MessageContext;
importorg.apache.Axis.handlers.BasicHandler;
importjava.util.Date;
publicclassLogHandler
extendsBasicHandler
{
publicvoidinvoke
(MessageContextmsgContext)
throwsAxisFault
{
/**Loganaccesseachtime
wegetinvoked.
*/
try{
HandlerserviceHandler
=msgContext.getService();
IntegernumAccesses=
(Integer)serviceHandler.getOption("accesses");
if(numAccesses==null)
numAccesses=newInteger(0);
numAccesses=newInteger
(numAccesses.intValue()+1);
Datedate=newDate();
Stringresult=
date+":service"+
msgContext.getTargetService()+
"accessed"+numAccesses+"time(s).";
serviceHandler.setOption
("accesses",numAccesses);
System.out.println(result);
}catch(Exceptione)
{
throwAxisFault.makeFault(e);
}
}
}
3、编写wsdd文件
deploy.wsdd
<deploymentxmlns=
"http://xml.apache.org/Axis/wsdd/"
xmlns:java=
"http://xml.apache.org/Axis/wsdd/providers/java">
<handlername="print"type="java:LogHandler"/>
<servicename="sayhello"
provider="java:RPC">
<requestFlow>
<handlertype="print"/>
</requestFlow>
<parametername="className"
value="server.SayHello"/>
<parametername="allowedMethods"
value="*"/>
</service>
</deployment>
3、将编译后的文件拷贝到Axis_HOME/WEB-INF/classes下,如:D: omcatwebappsAxisWEB-INFclasses
4、公布服务:
javaorg.apache.Axis.client.AdminClientdeploy.wsdd
5、天生clientstub文件
a:体例1
将SayHello.java拷贝到Axis_HOME/下,重定名为SayHello.jws,
实行上面的命令保存clientstub
javaorg.apache.Axis.wsdl.WSDL2Java
-pclienthttp://localhost:8080
/Axis/services/SayHello.jws?wsdl
b:体例2
实行以下命令天生SayHello.wsdl
javaorg.apache.Axis.wsdl.Java2WSDL
-oSayHello.wsdl-lhttp://localhost:8080
/Axis/services/SayHello-nsayhelloserver.SayHello
实行以下命令天生clientstub
javaorg.apache.Axis.wsdl.WSDL2Java
SayHello.wsdl-pclient
天生的stubclient文件列表为:
1.SayHello.java
2.SayHelloService.java。
3.SayHelloServiceLocator.java
4.SayHelloSoapBindingStub.java
6、编写客户端程序,编译并实行
publicclassSayHelloClient
{
publicstaticvoidmain(String[]args)
{
try
{
SayHelloServiceservice=newclient.
SayHelloServiceLocator();
client.SayHello_PortType
client=service.getSayHello();
StringretValue=client.getName("zhangsan");
System.out.println(retValue);
}
catch(Exceptione)
{
System.err.println
("Executionfailed.Exception:"+e);
}
}
}
你通过从书的数量和开发周期及运行速度来证明:net和ruby要比java简单。 |
|