1

我正在尝试发送带有嵌套参数的 SoapObject,但它会产生错误,尽管事实上我正在遵循 kSOAP 的指南......

我发送没有嵌套参数的 SoapObject 没有问题,但是一旦我必须发送嵌套,它就会崩溃......(唯一的区别是嵌套参数)......

这是我设置请求的方式:

void connection()
{
    Singleton service = Singleton.getInstance();
    String firstURL = service.getURL();
    URL = firstURL + "Attendance.svc";

    //Get parentID, parentToken
    String parentIDSingleton = service.getParentID();
    String parentTokenSingleton = service.getParentToken();

    //Get current time for GMT
    Calendar c = Calendar.getInstance(); 
    //Set format
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

    //Save in string
    String formattedDate = df.format(c.getTime());      

    //Initialize soap request
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapObject nestedParameters = new SoapObject(NAMESPACE, "planInfos");

    //Add parameters
    request.addProperty("nAttendeeId", "*some value");

    //Add nested parameters
    nestedParameters.addProperty("day:Date", formattedDate);
    nestedParameters.addProperty("day:PlannedStatus", "Syg");
    request.addSoapObject(nestedParameters);

    //Declare the version of the SOAP request
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

    envelope.dotNet=true;
    envelope.implicitTypes=true;
    envelope.setAddAdornments(false);

    //Prepare request
    envelope.setOutputSoapObject(request);

    //Set up the header
    Element parentID = new Element().createElement("ns", "parentId");
    parentID.addChild(Node.TEXT, parentIDSingleton);
    Element parentToken = new Element().createElement("ns", "parentToken");
    parentToken.addChild(Node.TEXT, parentTokenSingleton);
    Element authType = new Element().createElement("ns", "authType");
    authType.addChild(Node.TEXT, "Parent");
    Element kindergardenID = new Element().createElement("ns", "id");
    kindergardenID.addChild(Node.TEXT, "1");

    //Add the header
    Element header[] = {parentID, parentToken, authType, kindergardenID};
    envelope.headerOut = header;

    //Needed to make the internet call
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

    //Allow for debugging - needed to output the request
    androidHttpTransport.debug = true;

    try 
    {
        //this is the actual part that will call the web service
        androidHttpTransport.call(SOAP_ACTION, envelope);

        //Get the SoapResult from the envelope body.            
        SoapObject sResult = (SoapObject)envelope.bodyIn;

    } catch(org.xmlpull.v1.XmlPullParserException ex2)
    {               
        System.out.println(androidHttpTransport.requestDump.toString());

    }  catch (Exception e)
    {
        e.printStackTrace();
        System.out.println(androidHttpTransport.requestDump.toString());
    }
}

kSOAP2 网站上,他们说要设置这样的嵌套参数:

SoapObject users = new SoapObject(NAMESPACE, "users");
SoapObject john = new SoapObject(NAMESPACE, "user");
john.addProperty("name", "john");
john.addProperty("age", 12);
SoapObject marie = new SoapObject(NAMESPACE, "user");
john.addProperty("name", "marie");
john.addProperty("age", 27);
users.addSoapObject(john);
users.addSoapObject(marie);

这就是我所做的...

有任何想法吗???

我得到的错误:

05-03 10:46:45.313: W/System.err(1855): java.net.UnknownHostException: kindergardentest.sms2go.dk 05-03 10:46:45.329: W/System.err(1855): 在 java。 net.InetAddress.lookupHostByName(InetAddress.java:506) 05-03

10:46:45.329:W/System.err(1855):在 java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)05-03

10:46:45.329: W/System.err(1855): 在 java.net.InetAddress.getAllByName(InetAddress.java:256) 05-03

10:46:45.329: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:69)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:48)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)

05-03 10:46:45.347: W/System.err(1855): 在 org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)

05-03 10:46:45.371: W/System.err(1855): 在 org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)

05-03 10:46:45.371: W/System.err(1855): 在 org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153)

05-03 10:46:45.371: W/System.err(1855): 在 org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)

05-03 10:46:45.371: W/System.err(1855): 在 com.cim.daycare.AuthenticateConnection.connection(AuthenticateConnection.java:74)

05-03 10:46:45.377: W/System.err(1855): 在 com.cim.daycare.DayCareActivity$AuthenticateUser.doInBackground(DayCareActivity.java:308)

05-03 10:46:45.377: W/System.err(1855): 在 com.cim.daycare.DayCareActivity$AuthenticateUser.doInBackground(DayCareActivity.java:1)

05-03 10:46:45.377: W/System.err(1855): 在 android.os.AsyncTask$2.call(AsyncTask.java:185) 05-03 10:46:45.377: W/System.err(1855 ): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

05-03 10:46:45.377: W/System.err(1855): 在 java.util.concurrent.FutureTask.run(FutureTask.java:138) 05-03

10:46:45.377: W/System.err(1855): 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)

05-03 10:46:45.388: W/System.err(1855): 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

05-03 10:46:45.388: W/System.err(1855): 在 java.lang.Thread.run(Thread.java:1019) 05-03 10:46:45.388:

05-03 10:46:45.407: W/dalvikvm(1855): threadid=9: 线程退出未捕获异常 (group=0x40015560)

05-03 10:46:45.420:E/AndroidRuntime(1855):致命异常:AsyncTask #1 05-03

10:46:45.420: E/AndroidRuntime(1855): java.lang.RuntimeException: 执行 doInBackground() 时出错

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 android.os.AsyncTask$3.done(AsyncTask.java:200)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.FutureTask.setException(FutureTask.java:125)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.FutureTask.run(FutureTask.java:138) 05-03

10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)

05-03 10:46:45.420: E/AndroidRuntime(1855): at java.lang.Thread.run(Thread.java:1019) 05-03 10:46:45.420: E/AndroidRuntime(1855): 原因: java.lang.NullPointerException

05-03 10:46:45.420: E/AndroidRuntime(1855): at com.cim.daycare.DayCareActivity$AuthenticateUser.doInBackground(DayCareActivity.java:311)

05-03 10:46:45.420: E/AndroidRuntime(1855): at com.cim.daycare.DayCareActivity$AuthenticateUser.doInBackground(DayCareActivity.java:1)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 android.os.AsyncTask$2.call(AsyncTask.java:185)

05-03 10:46:45.420: E/AndroidRuntime(1855): 在 java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)

05-03 10:46:45.420: E/AndroidRuntime(1855): ... 4 更多 05-03

10:46:47.697: E/WindowManager(1855): Activity com.cim.daycare.DayCareActivity 泄露了最初添加在这里的窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@40517918

05-03 10:46:47.697: E/WindowManager(1855): android.view.WindowLeaked: Activity com.cim.daycare.DayCareActivity 泄露了窗口 com.android.internal.policy.impl.PhoneWindow$DecorView@40517918最初添加在这里

05-03 10:46:47.697: E/WindowManager(1855): 在 android.view.ViewRoot.(ViewRoot.java:258) 05-03

10:46:47.697: E/WindowManager(1855): 在 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.view.Window$LocalWindowManager.addView(Window.java:424) 05-03

10:46:47.697: E/WindowManager(1855): 在 android.app.Dialog.show(Dialog.java:241)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.ProgressDialog.show(ProgressDialog.java:107) 05-03

10:46:47.697: E/WindowManager(1855): 在 android.app.ProgressDialog.show(ProgressDialog.java:90) 05-03

10:46:47.697: E/WindowManager(1855): 在 com.cim.daycare.DayCareActivity$AuthenticateUser.onPreExecute(DayCareActivity.java:295)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.os.AsyncTask.execute(AsyncTask.java:391)

05-03 10:46:47.697: E/WindowManager(1855): 在 com.cim.daycare.DayCareActivity.onCreate(DayCareActivity.java:154)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.ActivityThread.access$1500(ActivityThread.java:117) 05-03

10:46:47.697: E/WindowManager(1855): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.os.Handler.dispatchMessage(Handler.java:99) 05-03

10:46:47.697: E/WindowManager(1855): 在 android.os.Looper.loop(Looper.java:123)

05-03 10:46:47.697: E/WindowManager(1855): 在 android.app.ActivityThread.main(ActivityThread.java:3683) 05-03

10:46:47.697: E/WindowManager(1855): 在 java.lang.reflect.Method.invokeNative(Native Method) 05-03

10:46:47.697: E/WindowManager(1855): 在 java.lang.reflect.Method.invoke(Method.java:507)

05-03 10:46:47.697: E/WindowManager(1855): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)

05-03 10:46:47.697: E/WindowManager(1855): 在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 05-03

10:46:47.697:E/WindowManager(1855):在 dalvik.system.NativeStart.main(本机方法)

4

1 回答 1

0

添加您的清单文件此权限:

<uses-permission android:name="android.permission.INTERNET" />

然后再试一次。

于 2012-05-04T08:47:36.337 回答