gpt4 book ai didi

java - 在 android 中调用 SOAP 服务的问题

转载 作者:行者123 更新时间:2023-11-29 20:05:23 25 4
gpt4 key购买 nike

你好 friend 我想像下面的代码一样集成 SOAP 服务

String METHOD_NAME = "processPayment";
String NAMESPACE = "http://paymentgateway.mcommerce/";
String URL = "http://182.19.20.182:81/mcommerce.webservices/pgService?wsdl";

Element authHeader = new Element();
authHeader.setNamespace(NAMESPACE);


Element username = authHeader.createElement(NAMESPACE, "userId");
username.addChild(Node.TEXT, "aJtlkG0NQTRBaLgVt4YC4A==");
authHeader.addChild(Node.ELEMENT, username);

Element password = authHeader.createElement(NAMESPACE, "password");
password.addChild(Node.TEXT, "7p/MAUl80KP+FdRERRyvlQ==");
authHeader.addChild(Node.ELEMENT, password);

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

request.addProperty("MCODE", "0021225252");
request.addProperty("TXNDATE", "12052015");
request.addProperty("TRANSREFNO", "20090824203454");
request.addProperty("MSISDN", "9879900088");
request.addProperty("AMT", 100.0);
request.addProperty("NARRATION", "TEXT");
request.addProperty("SURCHARGE", 5);
request.addProperty("FILLER1", "");
request.addProperty("FILLER2", "");
request.addProperty("FILLER3", "");
request.addProperty("FILLER4", "");
request.addProperty("FILLER5", "");
request.addProperty("mPIN", "1256");

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
envelope.headerOut = new Element[]{authHeader};

/*envelope.headerOut = new Element[1];
envelope.headerOut[0] = buildAuthHeader();*/

HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call("", envelope);
SoapObject response = (SoapObject) envelope.getResponse();
System.out.print("SOAP RESPONSE " + response);
} catch (Exception e) {
e.printStackTrace();
}

当我运行上面的代码时,我得到这样的错误

java.lang.RuntimeException: Cannot serialize: 100.0 at line
androidHttpTransport.call("", envelope);

我的服务中的 SoapAction 是空的,所以我没有在代码中提及,所以知道如何解决这个问题吗?

最佳答案

我想这行是罪魁祸首:

request.addProperty("AMT", 100.0);

注意 100.0 没有像所有其他属性值一样用双引号括起来。所以改成

request.addProperty("AMT", "100.0");

看看它是否有效。

关于java - 在 android 中调用 SOAP 服务的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35746139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com