1、编写代码方式:
packagecom.yudun.test;
importjava.rmi.RemoteException;
importorg.apache.axis.client.Call;
importorg.apache.axis.client.Service;
importorg.apache.axis.message.PrefixedQName;
importorg.apache.axis.message.SOAPHeaderElement;
importcom.cezanne.golden.user.Exception;
importcom.cezanne.golden.user.UserManagerServiceProxy;
importjavax.xml.namespace.QName;
importjava.net.MalformedURLException;
importjavax.xml.rpc.ServiceException;
importjavax.xml.soap.Name;
importjavax.xml.soap.SOAPException;
publicclasstestWebService{
publicstaticStringgetResult()throwsServiceException,MalformedURLException,RemoteException,SOAPException
{
//标识WebService的具体路径
Stringendpoint="WebService服务地址";
//创建Service实例
Serviceservice=newService();
//通过Service实例创建Call的实例
Callcall=(Call)service.createCall();
//将WebService的服务路径加入到call实例之中.
call.setTargetEndpointAddress(newjava.net.URL(endpoint));//为Call设置服务的位置
//由于需要认证,故需要设置调用的SOAP头信息。
NameheaderName=newPrefixedQName(newQName("发布的wsdl里的targetNamespace里的url","string_itemName"));
org.apache.axis.message.SOAPHeaderElementheader=newSOAPHeaderElement(headerName);
header.addTextNode("blablabla");
call.addHeader(header);
//SOAPHeaderElementsoapHeaderElement=newSOAPHeaderElement("发布的wsdl里的targetNamespace里的url","SoapHeader");
//soapHeaderElement.setNamespaceURI("发布的wsdl里的targetNamespace里的url");
//try
//{
//soapHeaderElement.addChildElement("string_itemName").setValue("blablabla");
//}
//catch(SOAPExceptione)
//{
//e.printStackTrace();
//}
//call.addHeader(soapHeaderElement);
//调用WebService的方法
org.apache.axis.description.OperationDescoper;
org.apache.axis.description.ParameterDescparam;
oper=neworg.apache.axis.description.OperationDesc();
oper.setName("opName");
param=neworg.apache.axis.description.ParameterDesc(newjavax.xml.namespace.QName("","arg0"),org.apache.axis.description.ParameterDesc.IN,newjavax.xml.namespace.QName("
param.setOmittable(true);
oper.addParameter(param);
param=neworg.apache.axis.description.ParameterDesc(newjavax.xml.namespace.QName("","arg1"),org.apache.axis.description.ParameterDesc.IN,newjavax.xml.namespace.QName("
param.setOmittable(true);
oper.addParameter(param);
param=neworg.apache.axis.description.ParameterDesc(newjavax.xml.namespace.QName("","arg2"),org.apache.axis.description.ParameterDesc.IN,newjavax.xml.namespace.QName("
param.setOmittable(true);
oper.addParameter(param);