展开全部
现在一般发布一个 webserivice 要么用 apache axis 要么用 XFire,下面这个例子是,用 apach axis 客户端来访问 webserivice。
package com.eastcompeace.axis;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Sample {
public static void main(String[] args) {
String url = "http://localhost:8080/axis/HelloWorld.jws";
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName("hello");
String strTemp = (String) call.invoke(new Object[] {"china"});
System.out.println(strTemp);
} catch (ServiceException ex) {
ex.printStackTrace();
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
}
package com.eastcompeace.axis;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class Sample {
public static void main(String[] args) {
String url = "http://localhost:8080/axis/HelloWorld.jws";
try {
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(url);
call.setOperationName("hello");
String strTemp = (String) call.invoke(new Object[] {"china"});
System.out.println(strTemp);
} catch (ServiceException ex) {
ex.printStackTrace();
} catch (RemoteException ex) {
ex.printStackTrace();
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询