KSoap2 SoapObject对象引用未设置为一个实例 [英] KSoap2 SoapObject Object Reference not set to an instance

查看:266
本文介绍了KSoap2 SoapObject对象引用未设置为一个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好,

我认为这是一个简单的问题,其他人可能能够提供缺少的环节来。我有一个的工作流程的WCF服务,我的.NET客户端可以正常通信。我已经打开的AppFabric下跟踪和可观赏服务呼叫正确执行,让我感觉很舒服的服务是没有问题的。我的Andr​​oid电话从不打的第一个跟踪点。

在Android的使用kso​​ap2(2.6.5),当我把这个行,我得到一个对象引用未设置错误:

  SoapObject响应=(SoapObject)envelope.getResponse();
 

对我来说这看起来很简单的信封必须为空,当我们试图访问它的exec GETRESPONSE我们有我们的错误,但在调试器它表明它作为一个有效的对象。 Furhter我找不到的文件来解释和每一个教程,我已经看到了这种方式左右.... ?????

有一件事情,不同的是,在.NET中我将创建一个对象传递让.NET对我来说序列化对象。在这里,我想补充的几个参数,这些参数都是字符串,但枚举我会告诉,因为它是一个可能的罪魁祸首。这是我的完整的Java实现:

 字符串NAMESPACE =htt​​p://tempuri.org/;
字符串METHOD_NAME =LiftDataExchange;
字符串SOAP_ACTION =htt​​p://tempuri.org/ILiftDataExchange/ProcessDataRequest;
字符串的URL =htt​​p://www.icyarmtesting.com/LiftDataExchange.xamlx;
字符串SOAP_REMOTE_NAMESPACE =htt​​p://schemas.datacontract.org/2004/07/IronMikeDataExchangeWorkflowService.Enum;

字符串x =;
ExchangeEnumerations ExrcsEnum = ExchangeEnumerations.GetNextWorkout;

//初始化SOAP请求
SoapObject请求=新SoapObject(命名空间METHOD_NAME);

//添加参数
的PropertyInfo piAct =新的PropertyInfo();
piAct.setName(行动);
piAct.setValue(ExrcsEnum);
piAct.setType(ExchangeEnumerations.class);
request.addProperty(piAct);

//声明SOAP请求的版本
SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping(SOAP_REMOTE_NAMESPACEExchangeEnumerations,ExchangeEnumerations.class,ExchangeEnumerationsEnumClass.getInstance());
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(要求);

//需要做互联网电话
HttpTransportSE androidHttpTransport =新HttpTransportSE(URL);
androidHttpTransport.debug = TRUE;
尝试
    {
  //这是将调用Web服务的实际组成部分
  androidHttpTransport.call(SOAP_ACTION,包);
  SoapObject响应=(SoapObject)envelope.getResponse();
  X = response.getProperty(0)的ToString();
}
赶上(例外五)......
 

下面是我的要求转储:

 <五:信封的xmlns:I =htt​​p://www.w3.org/2001/XMLSchema-instance的xmlns:D =HTTP://www.w3 .ORG / 2001 / XML模式的xmlns:C =http://schemas.xmlsoap.org/soap/encoding/的xmlns:V =http://schemas.xmlsoap.org/soap/envelope/>
    <五:页眉/>
    <五:身体与GT;
        < LiftDataExchange的xmlns =htt​​p://tempuri.org/ID =O0C:根=1>
            <用户名我:TYPE =D:字符串> STERILIZED_OUT< /用户名>
            <密码我:TYPE =D:字符串> STERILIZED_OUT< /密码>
            < ExerciseProgramID我:TYPE =D:字符串> STERILIZED_OUT< / ExerciseProgramID>
            < IncomingWorkoutData我:TYPE =D:字符串> STERILIZED_OUT< / IncomingWorkoutData>
            &lt;作用我:TYPE =N0:ExchangeEnumerations xmlns:n0="http://schemas.datacontract.org/2004/07/IronMikeDataExchangeWorkflowService.Enum">GetNextWorkout</Action>
        &LT; / LiftDataExchange&GT;
    &LT; / V:车身&GT;
&LT; / V:信封&GT;
 

下面是我的回应转储:

 &LT; S:信封XMLNS:S =htt​​p://schemas.xmlsoap.org/soap/envelope/&GT;
    &LT; S:车身&GT;
        &LT; S:故障&GT;
            &LT;故障code xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</fault$c$c>
            &LT;在faultstring XML:LANG =EN-US&GT;未将对象引用设置到对象的实例&LT; /在faultstring&GT;。
            &LT;详情&GT;
                &LT; ExceptionDetail的xmlns =htt​​p://schemas.datacontract.org/2004/07/System.ServiceModel的xmlns:I =htt​​p://www.w3.org/2001/XMLSchema-instance&GT;
                &LT; HELPLINK我:零=真实/&GT;
                &LT;的InnerException我:零=真实/&GT;
                &LT;消息&GT;未将对象引用设置到对象的实例&LT; /消息&GT;
                &LT;堆栈跟踪&GT;在System.ServiceModel.Activities.WorkflowOperationContext.HandleEndResumeBookmark(IAsyncResult的结果)及#xD;在System.ServiceModel.Activities.WorkflowOperationContext.OnResumeBookmark()及#xD;在System.ServiceModel.Activities.WorkflowOperationContext..ctor(Object []对象的投入,的OperationContext的OperationContext,字符串的operationName,布尔performanceCountersEnabled,布尔propagateActivity,交易的currentTransaction,WorkflowServiceInstance workflowInstance,IInvokeReceivedNotification通知,WorkflowOperationBehavior行为,ServiceEndpoint终点,时间跨度超时,AsyncCallback的回调,对象的状态)及#xD;在System.ServiceModel.Activities.Description.WorkflowOperationBehavior.WorkflowOperationInvoker.OnBeginServiceOperation(WorkflowServiceInstance workflowInstance,的OperationContext的OperationContext,对象[]输入,交易的currentTransaction,IInvokeReceivedNotification通知,时间跨度超时,AsyncCallback的回调,对象的状态)及#xD;在System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.PerformOperation()&#xD;在System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.HandleEndGetInstance(IAsyncResult结果)及#xD;在System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.Process()&#xD;在System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult..ctor(ControlOperationInvoker调用程序,对象[]输入,IInvokeReceivedNotification通知,时间跨度超时,AsyncCallback的回调,对象的状态)及#xD;在System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.InvokeBegin(对象实例,对象[]输入,IInvokeReceivedNotification通知,AsyncCallback的回调,对象的状态)及#xD;在System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc和放大器;放大器; RPC)及#xD;在System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc和放大器;放大器; RPC)及#xD;在System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc和放大器;放大器; RPC)及#xD;在System.ServiceModel.Dispatcher.MessageRpc.Process(布尔isOperationContextSet)</StackTrace><Type>System.NullReferenceException</Type></ExceptionDetail></detail></s:Fault></s:Body></s:Envelope>
 


更新:

切换到埃德温的方法调用了同样的结果。所以,我从KSoap2 2.6.5 3.0.0-RC4升级,现在我得到一个NullRefException。与以前的版本我会打的服务,并抛出对象未设置错误。有了这个版本,我不打的服务,并抛出NullRef。在code是改变的是我使用的KSOAP版本相同的唯一的事。我写了一个简单的服务(请记住,这些都是工作流服务),它接受一个字符串,改变它,踢一个字符串退了出去。

FWIW这里是我的code拨打电话:

 字符串SOAP_ACTION =htt​​p://tempuri.org/;
    字符串OPERATION_NAME =ChangeName;
    最后弦乐WSDL_TARGET_NAMESPACE = SOAP_ACTION;
    最后弦乐SOAP_ADDRESS =htt​​p://www.icyarmtesting.com/ServiceTest/Service1.xamlx;
    例外的例外;
    字符串ERRORMSG =;
    字符串TEST_URL =;

    SoapObject请求=新SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME);

    //的PropertyInfo piName =新的PropertyInfo();
    //piName.setName("UserName);
    //piName.setValue("ramjet);
    //piName.setType(String.class);
    //request.addProperty(piName);
    request.addProperty(用户名,冲压);

    SoapSerializationEnvelope包=新SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.dotNet = TRUE;
    envelope.setOutputSoapObject(要求);

    HttpTransportSE httpTransport = NULL;
    如果(!TEST_URL.equals())
        httpTransport =新HttpTransportSE(TEST_URL);
    其他
        httpTransport =新HttpTransportSE(SOAP_ADDRESS);



    对象响应=无效;
     尝试
     {
        httpTransport.call(SOAP_ACTION +IService /+ OPERATION_NAME,包);
        响应= envelope.getResponse();
      }
     赶上(SocketTimeoutException如果前)
     {
         ERRORMSG =无法连接;
          响应=无效;
         异常=前;
      }
      赶上(IOException异常即)
      {
       ERRORMSG =无法连接;
      响应=无效;
       异常= IE浏览器;
      }
       赶上(例外五)
       {
        ERRORMSG =无法连接;
        响应=无效;
        异常= E;
     }
 

解决方案

我知道它来不及回答这个问题,但我面临同样的问题,在我的code中的问题是,我输入的property.setname()不正确..请确保你写的方法参数的正确名称(复制过去,它从WSDL),我使用kso​​ap2 3.1.1顺便说一句!

Good Morning,

I "THINK" this is a simple problem that others may be able to provide the missing link to. I have a Workflow wcf service that my .NET clients can communicate with properly. I have turned on tracing under the appfabric and can watch service calls execute properly so I feel comfortable the service is not the problem. My android calls never hit the first trace point.

In android using ksoap2 (2.6.5) when I call this line I get an Object reference not set error:

SoapObject response = (SoapObject)envelope.getResponse();

To me this seems simple the envelope must be null and when we try to access it to exec the getResponse we have our error and yet in the debugger it shows it as a valid object. Furhter I can't find the documentation to explain and every tutorial I have seen has it this way so....?????

One thing that is different is that in .NET I would create an object pass the object letting .NET serialize it for me. Here I add several parameters and they are all strings but the enum I will show as it is a possible culprit. Here is my full java implementation:

String NAMESPACE = "http://tempuri.org/";
String METHOD_NAME = "LiftDataExchange";
String SOAP_ACTION = "http://tempuri.org/ILiftDataExchange/ProcessDataRequest";
String URL = "http://www.icyarmtesting.com/LiftDataExchange.xamlx";
String SOAP_REMOTE_NAMESPACE = "http://schemas.datacontract.org/2004/07/IronMikeDataExchangeWorkflowService.Enum";

String X = "";
ExchangeEnumerations ExrcsEnum = ExchangeEnumerations.GetNextWorkout;

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

//add parameters
PropertyInfo piAct = new PropertyInfo();
piAct.setName("Action");
piAct.setValue(ExrcsEnum);
piAct.setType(ExchangeEnumerations.class);
request.addProperty(piAct);

//Declare the version of the SOAP request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.addMapping(SOAP_REMOTE_NAMESPACE, "ExchangeEnumerations", ExchangeEnumerations.class, ExchangeEnumerationsEnumClass.getInstance());
envelope.dotNet = true;
envelope.setOutputSoapObject(request);

//Needed to make the internet call
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try 
    {          
  //this is the actual part that will call the webservice
  androidHttpTransport.call(SOAP_ACTION, envelope); 
  SoapObject response = (SoapObject)envelope.getResponse();
  X = response.getProperty(0).toString();
}
catch (Exception e)...... 

Here is my request dump:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
    <v:Header />
    <v:Body>
        <LiftDataExchange xmlns="http://tempuri.org/" id="o0" c:root="1">
            <UserName i:type="d:string">STERILIZED_OUT</UserName>
            <Password i:type="d:string">STERILIZED_OUT</Password>
            <ExerciseProgramID i:type="d:string">STERILIZED_OUT</ExerciseProgramID>
            <IncomingWorkoutData i:type="d:string">STERILIZED_OUT</IncomingWorkoutData>
            <Action i:type="n0:ExchangeEnumerations" xmlns:n0="http://schemas.datacontract.org/2004/07/IronMikeDataExchangeWorkflowService.Enum">GetNextWorkout</Action>
        </LiftDataExchange>
    </v:Body>
</v:Envelope>

Here is my response dump:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault</faultcode>
            <faultstring xml:lang="en-US">Object reference not set to an instance of an object.</faultstring>
            <detail>
                <ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <HelpLink i:nil="true"/>
                <InnerException i:nil="true"/>
                <Message>Object reference not set to an instance of an object.</Message>                
                <StackTrace>   at System.ServiceModel.Activities.WorkflowOperationContext.HandleEndResumeBookmark(IAsyncResult result)&#xD; at System.ServiceModel.Activities.WorkflowOperationContext.OnResumeBookmark()&#xD; at System.ServiceModel.Activities.WorkflowOperationContext..ctor(Object[] inputs, OperationContext operationContext, String operationName, Boolean performanceCountersEnabled, Boolean propagateActivity, Transaction currentTransaction, WorkflowServiceInstance workflowInstance, IInvokeReceivedNotification notification, WorkflowOperationBehavior behavior, ServiceEndpoint endpoint, TimeSpan timeout, AsyncCallback callback, Object state)&#xD; at System.ServiceModel.Activities.Description.WorkflowOperationBehavior.WorkflowOperationInvoker.OnBeginServiceOperation(WorkflowServiceInstance workflowInstance, OperationContext operationContext, Object[] inputs, Transaction currentTransaction, IInvokeReceivedNotification notification, TimeSpan timeout, AsyncCallback callback, Object state)&#xD; at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.PerformOperation()&#xD; at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.HandleEndGetInstance(IAsyncResult result)&#xD; at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult.Process()&#xD; at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.ControlOperationAsyncResult..ctor(ControlOperationInvoker invoker, Object[] inputs, IInvokeReceivedNotification notification, TimeSpan timeout, AsyncCallback callback, Object state)&#xD; at System.ServiceModel.Activities.Dispatcher.ControlOperationInvoker.InvokeBegin(Object instance, Object[] inputs, IInvokeReceivedNotification notification, AsyncCallback callback, Object state)&#xD; at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD; at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace><Type>System.NullReferenceException</Type></ExceptionDetail></detail></s:Fault></s:Body></s:Envelope>


UPDATE:

Switching to Edwin's method calls had the same result. So I upgraded from KSoap2 2.6.5 3.0.0-RC4 and now I am getting a NullRefException. With the prior version I would hit the service and throw the object not set error. With this version I do not hit the service and throw NullRef. The code is the same the only thing that changes is which version of KSoap I use. I wrote a simple service (Remember these are Workflow Services) that takes a string in, changes it, and kicks a string back out.

FWIW here is my code to make the call:

String SOAP_ACTION = "http://tempuri.org/";
    String OPERATION_NAME="ChangeName";
    final String WSDL_TARGET_NAMESPACE = SOAP_ACTION;
    final String SOAP_ADDRESS= "http://www.icyarmtesting.com/ServiceTest/Service1.xamlx";
    Exception exception;
    String ErrorMsg="";
    String TEST_URL="" ;

    SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);

    //PropertyInfo piName = new PropertyInfo();
    //piName.setName("UserName");
    //piName.setValue("ramjet");
    //piName.setType(String.class);
    //request.addProperty(piName);
    request.addProperty("UserName", "ramjet");

    SoapSerializationEnvelope  envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
    envelope.dotNet= true;
    envelope.setOutputSoapObject(request);

    HttpTransportSE httpTransport =null;
    if(!TEST_URL.equals(""))
        httpTransport = new HttpTransportSE(TEST_URL);
    else
        httpTransport = new HttpTransportSE(SOAP_ADDRESS);



    Object Response =null;
     try
     {
        httpTransport.call(SOAP_ACTION + "IService/" + OPERATION_NAME, envelope);
        Response = envelope.getResponse();
      }
     catch (SocketTimeoutException ex) 
     {
         ErrorMsg="Unable to connect";
          Response=null;
         exception=ex;
      }
      catch (IOException ie) 
      {
       ErrorMsg="Unable to connect";
      Response=null;
       exception=ie;
      }
       catch (Exception e) 
       {
        ErrorMsg="Unable to connect";
        Response=null;
        exception=e;
     }

解决方案

I know its too late to answer this but I faced the same problem and the problem in my code was that I typed the property.setname() incorrect .. make sure you wrote the correct name of the method parameter (copy past it from the wsdl) I'm using ksoap2 3.1.1 btw!

这篇关于KSoap2 SoapObject对象引用未设置为一个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆