我正在从 Android 向我的 Webservice (.NET) 发送我的对象,但 Webservice 告诉我他没有收到任何东西。我不知道问题出在哪里 - 是关于 Android 还是 Webservice?
方法等应该没问题,因为我能够从 Webservice 接收项目。而且我的方法看起来很好,不会抛出任何错误。
我的方法
final String METHOD_NAME = "SetMyProduct";
final String SOAP_ACTION = "http://tempuri.org/IService1/SetMyProduct";
myAdd objToSend = new myAdd();
objToSend.setProperty(0, "aaa");
objToSend.setProperty(1, "bbb");
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo pi = new PropertyInfo();
pi.setName("myAdd");
pi.setValue(objToSend);
pi.setType(myAdd.class);
request.addProperty(pi);
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
//soapEnvelope.bodyOut = request;
soapEnvelope.addMapping(NAMESPACE, myAdd.class.getSimpleName(), myAdd.class);
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(soapEnvelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, soapEnvelope);//call the eb service Method
//Log.i("soapEnvelope", String.valueOf(soapEnvelope));
//Log.i("request", String.valueOf(request));
} catch (Exception e) {
Log.e("error", String.valueOf(e));
}
我的添加类
public class myAdd implements KvmSerializable {
String Nazwa;
String Nazwa2;
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return Nazwa;
case 1:
return Nazwa2;
default:
return null;
}
}
@Override
public int getPropertyCount() {
return 2;//because you have 2 parameters
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Nazwa";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Nazwa2";
break;
default:break;
}
}
@Override
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
Nazwa = (String)arg1;
break;
case 1:
Nazwa2 = (String)arg1;
break;
default:
break;
}
}
}