朋友们,我想将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:无法序列化:行上的100.0 androidHttpTransport.call("",envelope);
我的SoapAction在我的服务中是空的,所以我没有在代码中提及所以任何想法我怎么能解决这个问题?
答案 0 :(得分:2)
我认为这条线是罪魁祸首:
request.addProperty("AMT", 100.0);
观察100.0不是所有其他属性值的双引号。所以把它改成
request.addProperty("AMT", "100.0");
看看它是否有效。