最近学习用CXF做SOAP WebService,但是客户端调用是其他公司用C#做的,所以基本不能指望其作出修改。
调用时,我的服务端遇到了如下一些报错
报错1
org.apache.cxf.interceptor.Fault: Unmarshalling Error: 意外的元素 (uri:”http://webservice.*.com/”, local:”arg”)。所需元素为<{}arg>
这里报错是因为SOAP请求xml中包含命名空间:http://webservice.*.com/
所以需要在接口方法中指明命名空间targetNamespace
另外需要注意,name属性的值需要与客户端调用的参数arg一致。
public String stopFuncion(@WebParam(name="arg",targetNamespace ="http://webservice.*.com/")String stopFuncionPara);
报错2
org.apache.cxf.interceptor.Fault: The given SOAPAction http://webservice.*.com/stopFunction does not match an operation.
报错是因为http请求Headers中包含如下header:
SOAPAction=[“http://webservice.*.com/stopFunction”]
服务端接口中stopFunction方法需要匹配该action:
@WebMethod(action="http://webservice.*.com/stopFunction")
public String stopFunction(@WebParam(name="arg",targetNamespace ="http://webservice.*.com/")String stopFunction);
报错解决