Java Web 服务与 Ksoap2 成功假错误
Java Webservice with Ksoap2 Succes False Error
帮帮我,我在上面工作了大约 5 个小时,它不起作用..
不幸的是,它总是给出这样的回应:
output: anyType{RequestResult=anyType{Success=false; Message=Object reference not set to an instance of an object.; }; }
我的 class 在这里:
public class WebServiceCallerImp implements WebServiceCaller{
static final String NAMESPACE="http://tempuri.org/";
static final String SERVICE_URL="http://93.94.199.145/IPhoneIPad/Service.asmx";
static String METHOD="GetForexStocksandIndexesInfo";
static String SOAP_ACTION = "http://tempuri.org/GetForexStocksandIndexesInfo";
@Override
public String GetForex(GetForexInput input) {
SoapObject request = new SoapObject(NAMESPACE,METHOD);
request.addProperty("IsIPAD", "false");
request.addProperty("DeviceID", "test");
request.addProperty("DeviceType", "ipad");
request.addProperty("RequestKey", "UmVxdWVzdElzVmFsaWQxNjowNToyMDEyIDExOjU0%%");
request.addProperty("Period", "Month");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(SERVICE_URL);
androidHttpTransport.debug=true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
System.out.println("output: "+response.toString());
return response.toString();
}
catch(Exception e){
System.out.println("@@@@: "+ e.toString());
}
return "null";
}}
我检查了来自 wsdl 的规则和参数:
http: //93.94.199.145/IPhoneIPad/Service.asmx?WSDL
及其方法:
http: //93.94.199.145/IPhoneIPad/Service.asmx?op=GetForexStocksandIndexesInfo
我哪里错了?
参数是结构请求{isipad, deviceid...}(参见 SoapUI)。
所以参数是这样做的,并将 implicitTypes 设置为 true 以防止类型属性:
SoapObject request = new SoapObject(NAMESPACE,METHOD);
SoapObject req_params = new SoapObject(NAMESPACE, "request");
req_params.addProperty("IsIPAD", "false");
req_params.addProperty("DeviceID", "test");
req_params.addProperty("DeviceType", "ipad");
req_params.addProperty("RequestKey", "UmVxdWVzdElzVmFsaWQxNjowNToyMDEyIDExOjU0%%");
req_params.addProperty("Period", "Month");
request.addSoapObject(req_params);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
不要问我为什么 return "Request is not Valid"。对于您提供的参数值,SoapUI 下有相同的响应。我想 "DeviceId" parameter is invalid 但真的不知道这个 WS ;)
希望能帮助到你
马辛
帮帮我,我在上面工作了大约 5 个小时,它不起作用..
不幸的是,它总是给出这样的回应:
output: anyType{RequestResult=anyType{Success=false; Message=Object reference not set to an instance of an object.; }; }
我的 class 在这里:
public class WebServiceCallerImp implements WebServiceCaller{
static final String NAMESPACE="http://tempuri.org/";
static final String SERVICE_URL="http://93.94.199.145/IPhoneIPad/Service.asmx";
static String METHOD="GetForexStocksandIndexesInfo";
static String SOAP_ACTION = "http://tempuri.org/GetForexStocksandIndexesInfo";
@Override
public String GetForex(GetForexInput input) {
SoapObject request = new SoapObject(NAMESPACE,METHOD);
request.addProperty("IsIPAD", "false");
request.addProperty("DeviceID", "test");
request.addProperty("DeviceType", "ipad");
request.addProperty("RequestKey", "UmVxdWVzdElzVmFsaWQxNjowNToyMDEyIDExOjU0%%");
request.addProperty("Period", "Month");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(SERVICE_URL);
androidHttpTransport.debug=true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse();
System.out.println("output: "+response.toString());
return response.toString();
}
catch(Exception e){
System.out.println("@@@@: "+ e.toString());
}
return "null";
}}
我检查了来自 wsdl 的规则和参数:
http: //93.94.199.145/IPhoneIPad/Service.asmx?WSDL
及其方法:
http: //93.94.199.145/IPhoneIPad/Service.asmx?op=GetForexStocksandIndexesInfo
我哪里错了?
参数是结构请求{isipad, deviceid...}(参见 SoapUI)。 所以参数是这样做的,并将 implicitTypes 设置为 true 以防止类型属性:
SoapObject request = new SoapObject(NAMESPACE,METHOD);
SoapObject req_params = new SoapObject(NAMESPACE, "request");
req_params.addProperty("IsIPAD", "false");
req_params.addProperty("DeviceID", "test");
req_params.addProperty("DeviceType", "ipad");
req_params.addProperty("RequestKey", "UmVxdWVzdElzVmFsaWQxNjowNToyMDEyIDExOjU0%%");
req_params.addProperty("Period", "Month");
request.addSoapObject(req_params);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.implicitTypes = true;
envelope.setOutputSoapObject(request);
不要问我为什么 return "Request is not Valid"。对于您提供的参数值,SoapUI 下有相同的响应。我想 "DeviceId" parameter is invalid 但真的不知道这个 WS ;) 希望能帮助到你 马辛