如何将参数传递给SOAP Web服务

时间:2013-12-18 06:56:01

标签: android

嗨,我是Android的新手我想将一些参数传递给soap web服务,但它在获取response.i时发出了NPE,并在评论中获得了NPE。请给我一些解决方案

这是我的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>

这是我的AsynchTask for soap

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;
    }
}

这是我的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)

提前致谢

3 个答案:

答案 0 :(得分:2)

请尝试进行一些更改

    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();
    }
}

我在使用xml发布数据时发布了具有json值的数据,因此有一些更改

答案 1 :(得分:1)

我使用以下代码将参数传递给方法

PropertyInfo info = new PropertyInfo();

//设置名称     info.setName(&#34; prefixText&#34);     //设定值     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);

这样我们就可以指定参数datatype,根据需要尝试it.alter代码

答案 2 :(得分:0)

不过,现有答案是正确的,但最好使用 $(".nav-primary .genesis-nav-menu, .nav-secondary .genesis-nav-menu, .nav-header .genesis-nav-menu, .nav-small .genesis-nav- // Sticky Navigation var headerHeight = $('.site-header').innerHeight(); var beforeheaderHeight = $('.before-header').outerHeight(); var abovenavHeight = headerHeight + beforeheaderHeight - 1; $(window).scroll(function(){ if ($(document).scrollTop() > abovenavHeight){ $('.navigation-container').addClass('fixed'); $('.nav-primary').addClass('fixed'); $('.nav-secondary').addClass('fixed'); } else { $('.navigation-container').removeClass('fixed'); $('.nav-primary').removeClass('fixed'); $('.nav-secondary').removeClass('fixed'); } }); 将参数发送到API,以解决性能问题。因此您可以使用以下代码进行操作:
在此示例中,AsyncTaskversion Number将被发送到soap Webservice:

device Id