Android 肥皂故障错误
我是 android 的初学者,这里我有使用网络服务的活动:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
GetBoundData val = new GetBoundData() {
};
PropertyInfo pi = new PropertyInfo();
pi.setName("GetBoundData");
pi.setValue(val);
pi.setType(GetBoundData.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
Marshal floatMarshal = new MarshalFloat();
envelope.addMapping(NAMESPACE, GetBoundData.class.getSimpleName(), GetBoundData.class);
floatMarshal.register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug =true;
TextView t = (TextView)this.findViewById(R.id.resultbox);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("aht requestDump is :"+androidHttpTransport.requestDump);
System.out.println("aht responseDump is :"+androidHttpTransport.responseDump);
} catch (Exception e) {
e.printStackTrace();
}
try {
Object result = (Object) envelope.bodyIn;
String s = result.toString();
t.setText(s);
} catch (ClassCastException e) {
// TODO Auto-generated catch block
e.printStackTrace();
t.setText("1");
}
在 GetBoundData 类中:
public abstract class GetBoundData implements KvmSerializable {
String Bound = "((-0.00021792948245596397, -0.0002648681402206421), (0.00021792948246868618, 0.0002648681402206421))";
String Zoom ="21";
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return Bound;
case 1:
return Zoom;
default:
return null;
}
}
public int getPropertyCount() {
return 2;//because you have 2 parameters
}
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Bound";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Zoom";
break;
default:break;
}
}
public void setval(String bound, String zoom) {
Bound = bound;
Zoom = zoom;
}
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
Bound = (String)arg1;
break;
case 1:
Zoom = (String)arg1;
break;
default:
break;
}
} 这
是 webservice xml
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GetBoundData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetBoundDataResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetBoundDataResult" type="tns:ArrayOfAnyType"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfAnyType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
,这里是 webservice 示例:
请求:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundData xmlns="http://tempuri.org/">
<Bound>string</Bound>
<Zoom>string</Zoom>
</GetBoundData>
</soap:Body>
</soap:Envelope>
响应:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundDataResponse xmlns="http://tempuri.org/">
<GetBoundDataResult>
<anyType />
<anyType />
</GetBoundDataResult>
</GetBoundDataResponse>
</soap:Body>
</soap:Envelope>
但是显示这个:
SoapFault - faultcode: 'soap:Server'
faultstring: 'Server was unable to process request. ---> Object reference not set to an
instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@44efb360
我将soapobject 与 getresponse() 一起使用,但发生了错误
I am a begginer in android,here I have activity that use web service:
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
GetBoundData val = new GetBoundData() {
};
PropertyInfo pi = new PropertyInfo();
pi.setName("GetBoundData");
pi.setValue(val);
pi.setType(GetBoundData.class);
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
Marshal floatMarshal = new MarshalFloat();
envelope.addMapping(NAMESPACE, GetBoundData.class.getSimpleName(), GetBoundData.class);
floatMarshal.register(envelope);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug =true;
TextView t = (TextView)this.findViewById(R.id.resultbox);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
System.out.println("aht requestDump is :"+androidHttpTransport.requestDump);
System.out.println("aht responseDump is :"+androidHttpTransport.responseDump);
} catch (Exception e) {
e.printStackTrace();
}
try {
Object result = (Object) envelope.bodyIn;
String s = result.toString();
t.setText(s);
} catch (ClassCastException e) {
// TODO Auto-generated catch block
e.printStackTrace();
t.setText("1");
}
and in GetBoundData class :
public abstract class GetBoundData implements KvmSerializable {
String Bound = "((-0.00021792948245596397, -0.0002648681402206421), (0.00021792948246868618, 0.0002648681402206421))";
String Zoom ="21";
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return Bound;
case 1:
return Zoom;
default:
return null;
}
}
public int getPropertyCount() {
return 2;//because you have 2 parameters
}
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch(arg0)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Bound";
break;
case 1:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Zoom";
break;
default:break;
}
}
public void setval(String bound, String zoom) {
Bound = bound;
Zoom = zoom;
}
public void setProperty(int arg0, Object arg1) {
switch(arg0)
{
case 0:
Bound = (String)arg1;
break;
case 1:
Zoom = (String)arg1;
break;
default:
break;
}
}
}
and this is webservice xml
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="GetBoundData">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetBoundDataResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetBoundDataResult" type="tns:ArrayOfAnyType"/>
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="ArrayOfAnyType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true"/>
</s:sequence>
</s:complexType>
</s:schema>
</wsdl:types>
here webservice sample:
request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundData xmlns="http://tempuri.org/">
<Bound>string</Bound>
<Zoom>string</Zoom>
</GetBoundData>
</soap:Body>
</soap:Envelope>
response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetBoundDataResponse xmlns="http://tempuri.org/">
<GetBoundDataResult>
<anyType />
<anyType />
</GetBoundDataResult>
</GetBoundDataResponse>
</soap:Body>
</soap:Envelope>
but show this :
SoapFault - faultcode: 'soap:Server'
faultstring: 'Server was unable to process request. ---> Object reference not set to an
instance of an object.' faultactor: 'null' detail: org.kxml2.kdom.Node@44efb360
I used soapobject with getresponse() but error occurred
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那是因为您有复杂类型(即对象),并且您只是添加“简单类型”属性。
检查我的答案这里,我详细解释了需要做什么.
您还必须创建与复杂类型匹配的本地类,这些本地类应该实现 kvmserialized,例如:
意味着在Web服务上,存在一个名为“GetBoundData”的类。因此,由于使用 ksoap2 您正在手动构建肥皂信封,因此您必须在应用程序中创建这样一个类,实现 kvmserialized (这是 ksoap2 序列化接口):
这就是您在本地构建类(对象,即复杂类型)在服务器上)。
然后,您必须添加必要的属性,构建信封,添加映射和编组并发送请求。这些步骤均在我上面提到的链接中进行了解释。
更新
我将向您解释这些是什么:
什么时候是 wsdl:message 这意味着它是 Web 服务所需的功能。
它有 ,这意味着它需要一个 GetBoundData 类型的参数,它不是原始类型,实际上它是一个复杂类型(对象)。
所以步骤如下:
1-你必须编写复杂类型 GetBoundData 的本地表示,即类(我已经在上面写过)
2- 在您的应用程序中,您必须创建(取决于您在哪里)一个函数,该函数将调用与 Web 服务上的“GetBoundDataSoapIn”相关的函数。因此,创建一个名称有意义的函数是一个好主意,即:
因此,检查 logCat 以查看请求和响应的形状,您将看到是否必须获取响应并解析它才能使用它,我是不确定你的反应是什么,但就我而言,它是一个多维数组,所以我必须使用 java 功能来解析它。
至于:
这只是告诉您网络服务发回响应。
Thats because you have complex type (ie Objects) and you are just adding "Simple type" property.
check my answer here, i explained in details what needs to be done.
You will also have to create local classes that match the complex type, these local classes should implement kvmserializable, for example:
means on the web service, there exists a class called "GetBoundData". So since using ksoap2 you are building manually the soap envelope, you will have to create such a class in your app , implementing kvmserializable ( which is a ksoap2 serialization interface):
This is how you build locally a match for the Classes (object,ie complex type) on the server).
Then you have to add the necessary properties, build the envelope, add Mapping and Marshalling and send the request. These Steps are all explained in the link i mentioned above.
UPDATE
I'll explain to you what these are:
When is it wsdl:message it means it is a function required on the web service.
it has , which means it requires a parameter of type GetBoundData which is not a primitive type, in fact it is a complex type (object).
So here are the steps:
1- you have to write a local representation , ie class, of the complex type GetBoundData ( i already wrote it above)
2- In your application you have to create (its up to u where) a function that will call the function related to "GetBoundDataSoapIn" on the web service. So its a good idead to create a function whose name is significat ie something like:
So check logCat to see the shape of request and response, and you'll see if you have to get the response and parse it to use it, i am not sure what your response will be, but in my case it was a multidimensional array, so i had to parse it using java functionalities.
as for:
this just tells you the web service sends back a response.
检查你的命名空间,方法名称。根据我的经验,当未与 Web 服务建立正确连接时,我们会收到此错误
Check you NameSpace ,Method Name . From my experience we get this error when proper connection is not made with webservice