2013-12-18 89 views
0

您好我可以新安卓android我想傳遞一些參數到soap網絡服務,但它在拋出NPE的同時得到response.i在評論哪裏正在獲取NPE。請給我提供了一些解決方案如何將參數傳遞給SOAP Web服務

這裏是我的XML

<soap:Body> 
<CreateNewTask xmlns="http://tempuri.org/"> 
    <description>string</description> 
    <userid>string</userid> 
    <task> 
    <Id>guid</Id> 
    <TaskMessage>string</TaskMessage> 
    <UserId>guid</UserId> 
    <AssignTaskTo>guid</AssignTaskTo> 
    <TaskStatus>boolean</TaskStatus> 
    <AssignDate>string</AssignDate> 
    <CompletionDate>dateTime</CompletionDate> 
    </task> 
    <assigntoId>string</assigntoId> 
    <comment>string</comment> 
</CreateNewTask> 

這裏是我的肥皂

public class New_Task extends AsyncTask<String, Void, String> { 
    String result = null; 
    Object resultRequestSOAP = null; 

    @Override 
    protected String doInBackground(String... params) { 
     // TODO Auto-generated method stub 
     SoapObject request = new SoapObject(NAMESPACE1, METHOD_NAME1); 

     request.addProperty("description", Singleton.Task_message);   
     request.addProperty("userid", Singleton.user_id);   
     request.addProperty("Id", Singleton.user_id);   
     request.addProperty("TaskMessage", Singleton.Task_message);   
     request.addProperty("UserId", Singleton.user_id);   
     request.addProperty("AssignTaskTo", Singleton.user_name);   
     request.addProperty("TaskStatus", "false"); 
     request.addProperty("AssignDate", "2013-12-18T11:12:08.000");   
     request.addProperty("CompletionDate", "2013-12-18T11:12:08.000");   
     request.addProperty("assigntoId", Singleton.user_id);      
     request.addProperty("comment", comment.getText().toString());   

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

     envelope.setOutputSoapObject(request); 
     envelope.dotNet = true; 
     try { 

      HttpTransportSE androidHttpTransport = new HttpTransportSE(URL1); 
      androidHttpTransport.debug = true; 
      androidHttpTransport.call(SOAP_ACTION1, envelope); 
      SoapObject soap_result = (SoapObject) envelope.getResponse(); 
      System.out.println("soap_result " + soap_result);   
      String requestDumpString = androidHttpTransport.requestDump;     
      System.out.println("requestDump : " + requestDumpString);    
      result = soap_result.toString(); // here i am getting NPE 
      System.out.println("result " + result); 

     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return result; 
    } 
} 

這裏AsynchTask是我logcat的結果NPE

12-18 13:35:59.052: W/System.err(13924): java.lang.NullPointerException 
12-18 13:35:59.062: W/System.err(13924): at com.example.woosuite.Woosuite_NewTask$New_Task.doInBackground(Woosuite_NewTask.java:183) 
12-18 13:35:59.062: W/System.err(13924): at com.example.woosuite.Woosuite_NewTask$New_Task.doInBackground(Woosuite_NewTask.java:1) 
12-18 13:35:59.062: W/System.err(13924): at android.os.AsyncTask$2.call(AsyncTask.java:287) 
12-18 13:35:59.062: W/System.err(13924): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 
12-18 13:35:59.062: W/System.err(13924): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 
12-18 13:35:59.072: W/System.err(13924): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 
12-18 13:35:59.072: W/System.err(13924): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 
12-18 13:35:59.072: W/System.err(13924): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 
12-18 13:35:59.072: W/System.err(13924): at java.lang.Thread.run(Thread.java:856) 

謝謝而你是用XML發佈的數據有了一些變化S IN提前

+0

有什麼問題?有什麼錯誤? – PankajAndroid

+0

是NPE here「SoapObject soap_result =(SoapObject)envelope.getResponse();」 – Eyes

+0

NPE?什麼是錯誤發佈它,我認爲它肥皂錯誤 – PankajAndroid

回答

1

請試試這個

SoapObject request = new SoapObject(NAMESPACE1, METHOD_NAME1); 

    PropertyInfo info = new PropertyInfo(); 
    info.setName("strInputData"); // .Net Funcation argument key 
    info.setType(String.class); 
    request.addProperty(info); 

    request.addProperty("description", Singleton.Task_message);   
    request.addProperty("userid", Singleton.user_id);   
    request.addProperty("Id", Singleton.user_id);   
    request.addProperty("TaskMessage", Singleton.Task_message);   
    request.addProperty("UserId", Singleton.user_id);   


    // Declare the version of the SOAP request 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request); 
    envelope.dotNet = true; 
    try { 
     HttpTransportSE androidHttpTransport = new HttpTransportSE(URL1); 
     androidHttpTransport.debug = true; 
     androidHttpTransport.call(SOAP_ACTION1, envelope); 

     SoapObject soap_result = (SoapObject) envelope.getResponse(); 
     System.out.println("soap_result " + soap_result);    
     String result = soap_result.toString(); // here i am getting NPE 
     System.out.println("result " + result); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

我有後數據用JSON值,因此有一些變化

+0

嗨,我可以知道這行說明:info.setName(「strInputData」); // .Net Funcation參數鍵 – Eyes

+0

您必須在.net中請求.net開發人員,其中有函數pubilc String saveData(String strInputData),因此參數是strInputData,您必須提及。 – PankajAndroid

0

我用來傳遞參數下面的代碼到方法

PropertyInfo info = new PropertyInfo();

//設置名稱 info.setName(「prefixText」); //設定值 info.setValue(mobileNum); //設置dataType info.setType(String.class); //將屬性添加到請求對象 request.addProperty(info);

info = new PropertyInfo(); 
//Set Name 
info.setName("count"); 
//Set Value 
info.setValue(5); 
//Set dataType 
info.setType(integer.class); 
//Add the property to request object 
request.addProperty(info); 
這樣我們可以指定參數的數據類型使

,嘗試it.alter根據代碼需要

相關問題