axis 添加 soapHeader 请求
来源:互联网 发布:java list sort 倒序 编辑:程序博客网 时间:2024/06/02 04:31
1、axis1.4
import java.net.URL;
import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.message.SOAPHeaderElement;
public class TestWebservice2 {
private final static String endpoint = "URL";
public static void main(String[] args) throws Exception {
// 产生 SOAP Header
SOAPHeaderElement cpHeader = new SOAPHeaderElement(
"urn:BackstageInterface", "auth");
cpHeader.setPrefix("");
cpHeader.setMustUnderstand(true);
SOAPElement ele = cpHeader.addChildElement("authcode");
ele.addTextNode("password");
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("urn:BackstageInterface", "sendSMS"));
call.addParameter("title", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("body", XMLType.XSD_STRING, ParameterMode.IN);
call.addParameter("fullName", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
// 设定 Header
call.addHeader(cpHeader);
System.out.println(call.invoke(new Object[]{"test ok","张潮","羊姬"}));
}
}
2、axis2
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPFactory;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import org.apache.axis2.saaj.SOAPHeaderImpl;
public class TestWebservice {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
// 这一步指定了该服务的提供地址
EndpointReference targetEPR = new EndpointReference(
"URL");
// 将option绑定到该服务地址
options.setTo(targetEPR);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("urn:BackstageInterface", "auth");
OMElement header = fac.createOMElement("auth", omNs);
OMElement authcode = fac.createOMElement("authcode", omNs);
authcode.setText("password");
header.addChild(authcode);
QName opAdd = new QName("urn:BackstageInterface", "sendSMS");
// 设置返回值类型
Class[] returnTypes = new Class[] { String.class };
// 设置调用的参数
Object[] opAddArgs = new Object[] { "test test", "test", "羊姬" };
// 调用服务,获得返回值
serviceClient.addHeader(header);
Object[] response = serviceClient.invokeBlocking(opAdd, opAddArgs,
returnTypes);
String res = (String) response[0];
if (res == null) {
System.out.println("wrong");
return;
}
System.out.println(res);
}
}
- axis 添加 soapHeader 请求
- axis设置SoapHeader
- .NET与Axis的SOAPHeader
- AXIS报文头SOAPHEADER认证
- [转]使用SoapHeader实现Soap请求验证
- 使用SoapHeader实现Soap请求验证
- 在soapheader中添加自定义信息
- java调用webservice-添加认证头(SOAPHeader)
- 利用AXIS添加WebService
- 使用SoapHeader实现Soap请求验证 转自(laruence)
- 利用axis请求webservice接口
- # C# 调用java的WebService添加SOAPHeader验证
- ISAG SOAPHEADER
- SoapHeader 使用
- webservice soapHeader
- AXIS
- Axis
- axis
- atomic_t原子操作
- Manacher算法
- jQuery操作input
- Javascript数组Array的forEach扩展方法
- 使用中的问题
- axis 添加 soapHeader 请求
- TRUNCATE TABLE和DELETE FROM区别
- activiti学习资料(获取流程图)
- Linux环境变量设置
- android 简易UDP通信模型
- 免费 SVN 服务器收集
- ACE_Singleton用法
- oraclle case when 用法大介绍
- socket 常用数据结构和操作函数归纳