2013-12-18 162 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根据代码需要

相关问题