Java Web服务与Ksoap2成功错误

时间:2015-01-06 17:26:04

标签: java android ksoap2

帮助我,我正在做大约5个小时的工作......

一切都不幸的是它总是给出这样的回应:

output: anyType{RequestResult=anyType{Success=false; Message=Object reference not set to an instance of an object.; }; }

我的课在这里:

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

及其methot:

http: //93.94.199.145/IPhoneIPad/Service.asmx?op=GetForexStocksandIndexesInfo

我的错误在哪里?

1 个答案:

答案 0 :(得分:4)

参数是结构请求{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);

不要问我为什么返回“请求无效”。对于您提供的参数值,SoapUI下的响应相同。我认为“DeviceId”参数无效但真的不知道这个WS;) 希望能帮助到你 马尔钦