?
?
使用JavaBean就可以生成,然后又wsdl文件。
有了wsdl文件可以生成客户端代码。
?
完成了webservice的实现。
?
?
现在使用开发工具开发实在是太快了。
?
- package?com.rx;
-
public?class?Calculate?{
-
????public?int?add(int?a,?int?b)?{
-
????????return?a?+?b;
- ????}
- ????
-
????public?String?sayHello(String?name)?{
- ????????
-
????????return?"Hello?:?"?+?name?+?",?You?are?welcome?!";
- ????}
- ????
- }
?
下面的是IBM RAD生成的代理类,其他省了。。。。。。 ? ? ? ?
-
- package?com.rx;
-
public?class?CalculateProxy?implements?com.rx.Calculate?{
-
??private?boolean?_useJNDI?=?true;
-
??private?String?_endpoint?=?null;
-
??private?com.rx.Calculate?__calculate?=?null;
- ??
-
??public?CalculateProxy()?{
- ????_initCalculateProxy();
- ??}
- ??
-
??private?void?_initCalculateProxy()?{
- ??
-
??if?(_useJNDI)?{
-
????try{
-
??????javax.naming.InitialContext?ctx?=?new?javax.naming.InitialContext();
-
??????__calculate?=?((com.rx.CalculateService)ctx.lookup("java:comp/env/service/CalculateService")).getCalculate();
- ??????}
-
????catch?(javax.naming.NamingException?namingException)?{}
-
????catch?(javax.xml.rpc.ServiceException?serviceException)?{}
- ??}
-
??if?(__calculate?==?null)?{
-
????try{
-
??????__calculate?=?(new?com.rx.CalculateServiceLocator()).getCalculate();
- ??????}
-
????catch?(javax.xml.rpc.ServiceException?serviceException)?{}
- ??}
-
??if?(__calculate?!=?null)?{
-
????if?(_endpoint?!=?null)
-
??????((javax.xml.rpc.Stub)__calculate)._setProperty("javax.xml.rpc.service.endpoint.address",?_endpoint);
-
????else
-
??????_endpoint?=?(String)((javax.xml.rpc.Stub)__calculate)._getProperty("javax.xml.rpc.service.endpoint.address");
- ??}
- ??
- }
-
public?void?useJNDI(boolean?useJNDI)?{
- ??_useJNDI?=?useJNDI;
-
??__calculate?=?null;
- ??
- }
-
public?String?getEndpoint()?{
-
??return?_endpoint;
- }
-
public?void?setEndpoint(String?endpoint)?{
- ??_endpoint?=?endpoint;
-
??if?(__calculate?!=?null)
-
????((javax.xml.rpc.Stub)__calculate)._setProperty("javax.xml.rpc.service.endpoint.address",?_endpoint);
- ??
- }
-
public?com.rx.Calculate?getCalculate()?{
-
??if?(__calculate?==?null)
- ????_initCalculateProxy();
-
??return?__calculate;
- }
-
public?int?add(int?a,?int?b)?throws?java.rmi.RemoteException{
-
??if?(__calculate?==?null)
- ????_initCalculateProxy();
-
??return?__calculate.add(a,?b);
- }
-
public?java.lang.String?sayHello(java.lang.String?name)?throws?java.rmi.RemoteException{
-
??if?(__calculate?==?null)
- ????_initCalculateProxy();
-
??return?__calculate.sayHello(name);
- }
- }
package?com.rx;
- import?java.rmi.RemoteException;
-
public?class?Test?{
- ????
- ????
-
????
-
-
????public?static?void?main(String[]?args)?{
-
????????Calculate?calculateProxy?=?new?CalculateProxy();
-
????????try?{
-
????????????calculateProxy.sayHello("china");
-
????????}?catch?(RemoteException?e)?{
- ????????????e.printStackTrace();
- ????????}
- ????}
- }
? ? 在JavaBean中调用webservice需要runtime下的2个包 默认路径: c:/parogram Files/IBM/SDP70/runtimes/base_v61/runtimescom.ibm.ws.admin.client_6.1.0.jarcom.ibm.ws.webservices.thinclient_6.1.0.jar
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|