DBMNG数据库管理与应用

才能是来自独创性。独创性是思维、观察、理解和判断的一种独特的方式。
当前位置:首页 > 经验分享 > Java组件

Axis2 java调用.net webservice接口“服务器未能识别 HTTP 头 SOAPAction 的值”的问题

问题一:org.apache.axis2.AxisFault: 服务器未能识别 HTTP 头 SOAPAction 的值


这个错误错误查了好久,最后发现对方给的资料里面忘记给命名空间地址了,我去真是头疼,注意的是需要加方法名称


http://tempuri.org/GetSign


问题二:org.apache.axis2.AxisFault: 服务器无法处理请求。 ---> 未将对象引用设置到对象的实例。

这个错误,也是满天飞的帖子其实是一个很小的问题,反斜杠


OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "");


标准吧,只要错那么点点,你就别想调通了,我把整个代码示例贴到下面:

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.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.client.ServiceClient;

import org.apache.axis2.transport.http.HTTPConstants;

 

 

public class SoapAxis {

     private static EndpointReference targetEPR = new EndpointReference("http://192.168.0.185/OnlinePaywebservice/platformws.asmx");

public static void main(String[] args) {

        Options options = new Options();

        options.setAction("http://tempuri.org/GetSign");// 调用接口方法

        options.setTo(targetEPR);

        options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.

 

 

        ServiceClient sender = null;

        try {

             sender = new ServiceClient();

             sender.setOptions(options);

             OMFactory fac = OMAbstractFactory.getOMFactory();

             OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "");

             OMElement method = fac.createOMElement("GetSign", omNs);

             OMElement name = fac.createOMElement("prestr", omNs);// 设置入参名称

             OMElement name2 = fac.createOMElement("key", omNs);// 设置入参名称

             name.setText("hawei");// 设置入参值

             name2.setText("6181a1fb89564b589283ad578baa7d5e");

             method.addChild(name);

             method.addChild(name2);

             method.build();

             System.out.println("method:" + method.toString());

             OMElement response = sender.sendReceive(method);

             System.out.println("response:" + response);

             OMElement elementReturn = response.getFirstElement();

             System.out.println("cityCode:" + elementReturn.getText());

          } catch (AxisFault e) {

             System.out.println("Error");

               e.printStackTrace();

          }

       }

}



问题三:org.apache.axis2.AxisFault: 服务器无法读取请求。 ---> XML 文档(1, 291)中有错误。 ---> 字符串“2014-12-09 02:03:00”不是有效的 AllXsd 值。


这个问题主要是日期格式问题,日期格式改成“2014-12-09T02:03:00”


String timestamp1 =new SimpleDateFormat("yyyy-MM-dd").format(nowDate);

String timestamp2 =new SimpleDateFormat("hh:mm:ss").format(nowDate);

String timestampString=timestamp1+" "+timestamp2;


问题四:SOAP头如何加

        public static void addValidation(ServiceClient serviceClient) {

OMFactory fac = OMAbstractFactory.getOMFactory();

OMNamespace omNs = fac.createOMNamespace(tns, "");

OMElement header = fac.createOMElement("CredentialSoapHeader", omNs);

OMElement appId = fac.createOMElement("AppID", omNs);

//

appId.setText("145");

header.addChild(appId);

System.out.println("header:" + header.toString());

serviceClient.addHeader(header);

}


原文:https://blog.csdn.net/zhangman117/article/details/41801381 

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号