创建服务器端
1.创建一个接口
IMyService.java
package com.test.service; import java.util.List; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; @WebService(targetNamespace = "http://www.webservice.com") public interface IMyService { // 传递header信息 @WebResult(name = "user") public List<User> list(@WebParam(header = true, name = "authInformation") String authInformation); }
2.创建实现接口的类
MyServiceImpl.java
package com.test.service; import java.util.ArrayList; import java.util.List; import javax.jws.WebService; @WebService(endpointInterface = "com.test.service.IMyService", targetNamespace = "http://www.webservice.com") public class MyServiceImpl implements IMyService { private static List<User> users = new ArrayList<User>(); public MyServiceImpl() { users.add(new User(1, "admin", "管理员", "111111")); } @Override public List<User> list(String authInformation) { // 打印客户端传递过来的头部信息 System.out.println(authInformation); return users; } }
3.开启服务
MyServer.java
package com.test.service; import javax.xml.ws.Endpoint; public class MyServer { public static void main(String[] args) { String address = "http://localhost:9999/server"; // 发布服务的实现类 Endpoint.publish(address, new MyServiceImpl()); } }
4.测试类TestSoap.java
// header头部消息传递 @Test public void test04() { try { // 创建服务 URL url = new URL("http://localhost:9999/server"); QName qname = new QName("http://www.webservice.com", "MyServiceImplService"); Service service = Service.create(url, qname); // 创建Dispatch Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName("http://www.webservice.com", "MyServiceImplPort"), SOAPMessage.class, Service.Mode.MESSAGE); // 创建SOAP的body消息 SOAPMessage message = MessageFactory.newInstance().createMessage(); SOAPEnvelope envelope = message.getSOAPPart().getEnvelope(); SOAPBody body = envelope.getBody(); // 创建SOAP的header消息 SOAPHeader header = envelope.getHeader(); if (header == null) { header = envelope.addHeader(); } QName hname = new QName("http://www.webservice.com", "authInformation", "ns"); header.addHeaderElement(hname).setValue("12345"); // 根据QName创建相应的节点 QName ename = new QName("http://www.webservice.com", "list", "ns"); body.addBodyElement(ename); message.writeTo(System.out); System.out.println("\n invoking..."); // 通过dispatch传递消息,返回响应消息 SOAPMessage response = dispatch.invoke(message); response.writeTo(System.out); System.out.println(); // 将响应的消息转换为dom对象 Document doc = response.getSOAPBody().extractContentAsDocument(); NodeList userList = doc.getElementsByTagName("user"); Unmarshaller unmarshaller = JAXBContext.newInstance(User.class).createUnmarshaller(); for (int i = 0; i < userList.getLength(); i++) { User user = (User) unmarshaller.unmarshal(userList.item(i)); System.out.println(user.getNickname()); } } catch (SOAPException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JAXBException e) { e.printStackTrace(); } }
运行结果:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header><ns:authInformation xmlns:ns="http://www.webservice.com">12345</ns:authInformation></SOAP-ENV:Header><SOAP-ENV:Body><ns:list xmlns:ns="http://www.webservice.com"/></SOAP-ENV:Body></SOAP-ENV:Envelope>
invoking...
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Header/><S:Body><ns2:listResponse xmlns:ns2="http://www.webservice.com"><user><id>1</id><nickname>管理员</nickname><password>111111</password><username>admin</username></user></ns2:listResponse></S:Body></S:Envelope>
管理员
在服务器端也会把设置的头部信息打印出:12345
相关推荐
在Web-service 调用SOAP 新增加SOAP的配置信息。用于验证用户信息。
cxf soap header cxf soap header cxf soap header cxf soap header
NULL 博文链接:https://iamliming.iteye.com/blog/1399257
解决Delphi的SOAP Header问题
通过SOAP header对client 进行验证 此例子包括Web services 以及客户端
WebServices在服务端和客户端使用SOAP消息格式来传递数据,我们使用Servlet来模拟SOAP消息的客户端和服务端。
基于.NET的 SOAP Header and SOAP Extensions 扩展Webservice服务程序例子。
SOAP SDK是用于微软的SOAP消息处理包,主要用于处理SOAP消息
创建soap消息的多种方式以及WSDL举例代码
Axis2 通过soap header进行授权服务 客户端根据是否生产stub客户端代码采用两种形式实现。
适用于soap消息的发送与接收org.apache.soap.Envelope envelope = new org.apache.soap.Envelope();
4.2 SOAP Header 4.2.1 Use of Header Attributes 4.2.2 SOAP actor Attribute 4.2.3 SOAP mustUnderstand Attribute 4.3 SOAP Body 4.3.1 Relationship between SOAP Header and Body 4.4 SOAP Fault 4.4.1 ...
这使 SOAP能够被用于从消息传递到RPC的各种系统。 SOAP的主要设计目标是简单性和可扩展性 ,这意味着传统的消息系统和分布对象系统的某些性质不是SOAP规范的一部分。这些性质包括: 分布式碎片收集 成批传送消息 对象...
易语言soap消息解析源码,soap消息解析,init,eachMethod,getMethodReturnInfo,getMethodInfo,getElementName,IsContinue,invoke,getTargetNamespace,parseError
对于使用 ASP.NET 创建的 XML Web services 和它们的使用 SOAP 与 XML Web services 方法进行通信的客户端来说,可以使用一种复杂的机制来控制发送到服务器和从服务器接收的 SOAP 消息的格式。
对wsdl的格式进行分析,主要讲解soap服务中rpc和doucumnet的不同之处。
thinkphp内使用soap 把下载的soap解压放到ThinkPHP\Extend\Vendor目录下 名字是soap 调用方法: function test($url,$method,$data){ vendor('soap.class#nusoap'); //从soap目录导class.nusoap.php类文件 $...
采用custom SOAP Header实现的 .NET web service 的权限控制源码例子。
SOAP以XML形式提供了一个简单、轻量的用于在分散或分布环境中交换结构化和类型信息的机制。SOAP本身并没有定义任何应用程序语义,如编程模型或特定语义的实现;...这使SOAP能够被用于从消息传递到RPC的各种系统
soap消息解析.rar