使用axis呼叫webservice介面
package msdev.yd.interfaceRequest;
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import org.apache.axis.Constants;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
/**
* 使用axis 呼叫 webservice
* @author hzz
*/
public class TestWebservice
{
public static void main(String[] args) {
try {
//wsdl路徑 不帶wsdl字尾
String url = "http://10.0.11.5//services/SubmitRequest";
//namespace路徑
String nampspace = "http://webservices.submitRequest.weaver.com.cn";
Service service = new Service();
Call call =(Call) service.createCall();
call.setTargetEndpointAddress(new URL(url));
call.setOperationName(new QName(nampspace, "submitRequest")); // wsdl裡面描述的介面名稱
call.setEncodingStyle("UTF-8");
call.addParameter(new QName(nampspace, "requestData"), Constants.XSD_STRING, ParameterMode.IN);
call.setReturnType(Constants.XSD_STRING);
String result =(String) call.invoke(new Object[] {"paramvalue"});//傳入引數並返回返回值
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
}
}