关于用JAX-WS调用webservice异常:Server did not recognize the value of HTTP Header SOAPAction: .
来源:互联网 发布:天猫魔盒网络无法连接 编辑:程序博客网 时间:2024/06/05 08:49
在调用一个webservice接口的时候发现用wsimport 生成客户端代码调用正常,但是通过soap消息直接调用则抛异常:
Server did not recognize the value of HTTP Header SOAPAction: .
经过长时间搜索找到这篇文章:http://www.tuicool.com/articles/RBVrUv
文章指出“在实现SOAP规范1.1中JAX-WS并不需要SOAPAction,但.NET中是需要的,哪怕是空。这就导致了上面的异常。”
在我这里调用的接口正是.net开发提供的。解决办法是:
1、JAX-WS中加入SOAPAction并设置其值为空,可惜JAX-WS没提供相关设置API,但CFX、axis等开源框架提供了API;2、设置.NET不使用SOAPAction,而使用<Body>XML 元素之后的第一个子元素做为路由RoutingStyle=SoapServiceRoutingStyle.RequestElement
作为接口调用方,我们可能没办法要求接口提供方作出修改,那么就可以采用第一种方法。经过实测,使用axis2调用成功。靠谱。axis依赖包如下:
<dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>1.5.1</version> <type>pom</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>1.5.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-kernel</artifactId> <version>1.5.1</version> <type>jar</type> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>org.apache.axis2.osgi</artifactId> <version>1.5.1</version> </dependency>
axis2的使用方法可参考这篇文章:http://blog.csdn.net/xiang520jl/article/details/15504175
当然了,用客户端代码调用也没什么不好。
由于怕第一篇参考文章链接失效,在这里,拷贝原文:
Java调用.Net写的WebService报异常:服务器未能识别 HTTP 头 SOAPAction 的值
异常及解决方案
使用JAX-WS调用.Net写的WebService报了如下异常:
javax.xml.ws.soap.SOAPFaultException: System.Web.Services.Protocols.SoapException: 服务器未能识别 HTTP 头 SOAPAction 的值: ....网络上很多信息都提示说,给.NET的WebService类(即.asmx文件下的类)添加属性:
[SoapDocumentService(RoutingStyle=SoapServiceRoutingStyle.RequestElement)]即可解决。
但你知道为什么吗?
虽然JAVA和.NET都是实现W3C制定的WebService规范,但其实两者在实现上并没有完全保持一致,在实现SOAP规范1.1中JAX-WS并不需要SOAPAction,但.NET中是需要的,哪怕是空。这就导致了上面的异常。
那么SOAPAction到底是作什么的呢?
SOAPAction 被用来标识SOAP HTTP请求的目的地。
在.NET中的实现原理是这样的:默认情况下,.asmx 处理程序使用 SOAPAction 头的值来执行消息调度。当客户端调用WebService时,.asmx 处理程序会通过查看SOAPAction确定要调用哪个方法。如:
POST /math/math.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/Add" <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Add xmlns="http://tempuri.org/"> <x>33</x> <y>66</y> </Add> </soap:Body> </soap:Envelope>通过SOAPAction可以确定要调用Add方法。
SOAP信息中还有种路由方式那就是使用<Body>XML 元素之后的第一个子元素,如:
POST /math/math.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "" <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <Add xmlns="http://tempuri.org/"> <x>33</x> <y>66</y> </Add> </soap:Body> </soap:Envelope>当SOAPAction为空时,则使用<soap:Body> 第一个子元素加上其命名空间来路由:http://tempuri.org/Add。这就是上面的设置
RoutingStyle=SoapServiceRoutingStyle.RequestElement
SoapServiceRoutingStyle是枚举类型:- SoapAction :SOAP 消息是根据 SOAPActionHTTP 标头路由的,默认值。
- RequestElement :SOAP 消息是根据 SOAP 消息中 <Body>XML 元素之后的第一个子元素路由的。
解决方案
所以有两种解决方案可以处理这个异常:
- JAX-WS中加入SOAPAction并设置其值为空,可惜JAX-WS没提供相关设置API,但CFX、axis等开源框架提供了API;
- 设置.NET不使用SOAPAction,而使用<Body>XML 元素之后的第一个子元素做为路由
RoutingStyle=SoapServiceRoutingStyle.RequestElement
- 关于用JAX-WS调用webservice异常:Server did not recognize the value of HTTP Header SOAPAction: .
- Server did not recognize the value of HTTP Header SOAPAction
- 解决XFireFault: Server did not recognize the value of HTTP Header SOAPAction: .
- DLL调用异常:The value of ESP was not properly......
- MyEclipse6.5 用jax-ws调用webservice(1)
- 用JAX-WS开发webservice
- Java调用.Net写的WebService报异常:服务器未能识别 HTTP 头 SOAPAction 的值
- Java调用.Net WebService 发生异常:服务器未能识别 HTTP 头 SOAPAction 的值
- 别人用jax-ws发布的webservice,我尝试了用axis调用webservice即wsdl可以。下面尝试另一种方式调用,用jax-ws方式去调用
- jax-ws webservice编程
- JAX-WS WebService
- JAX-WS实现WebService
- Jax WS发布webservice
- JAX-WS,WebService实例
- jax-ws webservice编程
- JAX-WS WebService发布
- WebService -- JAX-WS : 入门
- webService之JAX-WS
- springAOP事物管理不生效原因总结
- C/C++面试题(2)——查找链表中倒数第k个数
- 倒计时
- java设计模式之工厂方法模式
- activemq中多个consumer引起接收不到信息
- 关于用JAX-WS调用webservice异常:Server did not recognize the value of HTTP Header SOAPAction: .
- @SneakyThrows 注解
- 控制Shader只写入深度值
- GDT,LDT,GDTR,LDTR 详解,包你理解透彻
- 怎样从user版本中提取应用数据
- new和malloc
- php下ftp扩展安装
- Python 代码获取对应的网址
- YARN的内存和CPU配置