gpt4 book ai didi

android - KSoap2 SoapObject 对象引用未设置为实例

转载 作者:太空宇宙 更新时间:2023-11-03 11:17:18 27 4
gpt4 key购买 nike

我认为这是一个简单的问题,其他人也许能够提供缺失的链接。我有一个 Workflow wcf 服务,我的 .NET 客户端可以与之正确通信。我已经在 appfabric 下打开跟踪并且可以看到服务调用正确执行,所以我觉得服务不是问题。我的 Android 调用从未到达第一个跟踪点。

在使用 ksoap2 (2.6.5) 的 Android 中,当我调用此行时,我得到一个 Object reference not set 错误:

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

对我来说,这看起来很简单,信封必须为空,当我们尝试访问它以执行 getResponse 时,我们遇到了错误,但在调试器中它显示为有效对象。此外,我找不到文档来解释,我看到的每个教程都是这样......?

有一点不同的是,在 .NET 中我会创建一个对象传递对象,让 .NET 为我序列化它。在这里,我添加了几个参数,它们都是字符串,但我将显示枚举,因为它可能是罪魁祸首。这是我的完整 Java 实现:

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)......

这是我的请求转储:

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

这是我的响应转储:

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

更新:

切换到 Edwin 的方法调用具有相同的结果。所以我从 KSoap2 2.6.5 升级到 3.0.0-RC4,现在我得到一个 NullRefException。使用以前的版本我会点击服务并抛出对象未设置错误。使用此版本,我不会点击服务并抛出 NullRef。代码是一样的,唯一不同的是我使用的是哪个版本的 KSoap。我编写了一个简单的服务(记住这些是工作流服务),它接收一个字符串,对其进行更改,然后踢出一个字符串。

FWIW 这是我调用电话的代码:

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

最佳答案

更改以下内容:

SoapObject response = (SoapObject)envelope.getResponse();
X = response.getProperty(0).toString();

成为:

SoapObject response = (SoapObject)envelope.bodyIn;
if(response != null)
{
X=response.getProperty(0).toString();
}

关于android - KSoap2 SoapObject 对象引用未设置为实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14526892/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com