1.新建普通的Java工程
?
2.工程上右键添加Framework支持
选择Apache Axis 1.2
3.在弹出的生成Java Code界面输入wsdl地址和输出路径,其他可留空。
4.修改生成的HelloWorldClient代码
package example;
import org.apache.axis.message.SOAPHeaderElement;
import test.*;
import javax.xml.soap.SOAPException;
public class HelloWorldClient
{
public static void main(String[] argv) {
try {
Tdcus921ServiceLocator locator = new Tdcus921ServiceLocator();
Tdcus921 service = locator.gettdcus921SoapPort();
// 添加认证信息
((Tdcus921SoapBindingStub)service).setUsername("admin");
((Tdcus921SoapBindingStub)service).setPassword("123456");
//添加额外的头信息
try {
SOAPHeaderElement headerElement = new SOAPHeaderElement(locator.gettdcus921SoapPortAddress(),"Activation");
headerElement.addChildElement("unit").addTextNode("999");
((Tdcus921SoapBindingStub)service).setHeader(headerElement);
} catch (SOAPException e) {
e.printStackTrace();
}
// 请求参数
CreateRequestType crt = new CreateRequestType();
CreateRequestTypeDataAreaTdcus921 tdcus = new CreateRequestTypeDataAreaTdcus921();
tdcus.setId("20");
tdcus.setName("tesa");
tdcus.setPhone("1511234121323");
tdcus.setPwd("123");
tdcus.setText("测试测试");
CreateRequestTypeDataAreaTdcus921 [] list = new CreateRequestTypeDataAreaTdcus921[]{tdcus};
crt.setDataArea(list);
CreateResponseType responseType = service.create(crt);
//响应参数
CreateResponseTypeDataAreaTdcus921 ct [] = responseType.getDataArea();
for(CreateResponseTypeDataAreaTdcus921 c : ct)
{
System.out.println("ok:"+c.getId());
}
} catch (javax.xml.rpc.ServiceException ex) {
ex.printStackTrace();
} catch (java.rmi.RemoteException ex) {
ex.printStackTrace();
}
}
}
5.后续还想在此工程上生成wsdl代码时,点击tools的webservice工具
?
|