1、调用方式介绍
2、动态调用WebService
package com.majun.xml;
import java.util.Map;
importjavax.xml.namespace.QName;
importjavax.xml.soap.MessageFactory;
importjavax.xml.soap.SOAPBody;
importjavax.xml.soap.SOAPBodyElement;
importjavax.xml.soap.SOAPElement;
importjavax.xml.soap.SOAPMessage;
importjavax.xml.ws.BindingProvider;
importjavax.xml.ws.Dispatch;
importjavax.xml.ws.Service;
importjavax.xml.ws.WebServiceException;
importjavax.xml.ws.soap.SOAPBinding;
public classDLLClient
{
// 名字空间
publicstatic final String targetNamespace = "http://service.billInface.boss.gmt/";
//服务名
publicstatic final String serName = "BillWebServiceService";
//端口名
publicstatic final String pName = "BillWebServicePort";
//服务地址
public static final StringendpointAddress = "http://localhost:8080/BillInface/BillWebServicePort?wsdl";
//方法名
public static final String OPER_NAME ="getInBillingLoginInfo";
//参数名
public static final String INPUT_NMAE = "arg0";
public static void main(String[] args) throws Exception
{
QName serviceName = new QName(targetNamespace, serName);
QName portName = new QName(targetNamespace,pName);
javax.xml.ws.Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,endpointAddress);
Dispatch<SOAPMessage> dispatch =service.createDispatch(portName,
SOAPMessage.class, Service.Mode.MESSAGE);
BindingProvider bp = (BindingProvider)dispatch;
Map<String, Object>rc = bp.getRequestContext();
rc.put(BindingProvider.SOAPACTION_USE_PROPERTY,Boolean.TRUE);
rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,OPER_NAME);
MessageFactory factory =((SOAPBinding)bp.getBinding()).getMessageFactory();
SOAPMessage request = factory.createMessage();
SOAPBody body = request.getSOAPBody();
QName payloadName = new QName(targetNamespace,OPER_NAME, "ns1");
SOAPBodyElement payload =body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement(INPUT_NMAE);
message.addTextNode("x");
SOAPMessage reply = null;
try
{
reply = dispatch.invoke(request);
}
catch (WebServiceException wse)
{
wse.printStackTrace();
}
SOAPBody soapBody = reply.getSOAPBody();
SOAPBodyElement nextSoapBodyElement =(SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement =(SOAPElement)nextSoapBodyElement.getChildElements().next();
System.out.println("获取回应信息为:" +soapElement.getValue());
}
以上文章转自 http://blog.sina.com.cn/s/blog_6458bf440100lf82.html
特别感谢马儿作者的文章帮我解决了WebService远程调用的解决方法,特此感谢作者。