机器人的SOAPFault错误 [英] android soapfault error

查看:583
本文介绍了机器人的SOAPFault错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在android的一个初学者,在这里我有活动使用的Web服务:

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

和在GetBoundData类:

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

} }

这是Web服务的XML

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>

下面的web服务示例:

here webservice sample:

要求:

<?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 used soapobject with getresponse() but error occurred

推荐答案

那是因为你有复杂类型(即对象)和刚刚添加的简单型属性。
检查我的回答<一href="http://stackoverflow.com/questions/9023442/android-wsdl-web-service-ksoap2/9042267#9042267">here,我详细解释了什么是需要做的事情。
您还可以创建本地类匹配的复杂类型,这些本地类应实现kvmserializable,例如:

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:

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

是指在网络服务中,存在一类叫GetBoundData。如此以来,使用kso​​ap2您手动构建SOAP信封,你将不得不在你的应用程序创建一个这样的类,实现kvmserializable(这是一个ksoap2串行接口):

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

public class GetBoundData implements KvmSerializable {

    String Bound; 
    String Zoom;

    @Override
    public Object getProperty(int arg0) {
    switch (arg0){
        case 0:
            return Bound;
        case 1:
            return Zoom;
        default:
            return null;
            }
    }

    @Override
    public int getPropertyCount() {
        return 2;//because you have 2 parameters
    }

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

    }

    @Override
    public void setProperty(int arg0, Object arg1) {
    switch(arg0)
    {
        case 0:
            Bound =  (String)arg1;
            break;
        case 1:
            Zoom =  (String)arg1;           
            break;
        default:
            break;
    }
}

这是你如何在本地建立一个(即复杂类型的对象,)在服务器上匹配的类)。 然后,你需要添加必要的属性,打造信封,添加制图和编组,并发送请求。这些步骤是在我上面提到的链接都解释说。

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:

<wsdl:message name="GetBoundDataSoapIn"> 
<wsdl:part name="parameters" element="tns:GetBoundData"/> 
</wsdl:message> 

当它是WSDL:邮件的意思是它在网络服务所需的功能。 它有 ,这意味着它需要的类型GetBoundData的参数,它不是原始的类型,实际上它是一个复杂的类型(对象)。
因此,这里的步骤:
1 - 你必须写一个地方重新presentation复杂类型GetBoundData,即类,(我上面已经写的)
2-在你的应用程序,你必须创建(其高达ü在哪里)功能,将调用Web服务相关的GetBoundDataSoapIn的功能。因此,它的一个很好idead来创建其名称的函数是significat即是这样的:

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:

 public GetBoundData getBoundData()
 {
  try
    {
        SoapObject sobj = new SoapObject(YOUR_NAMESPACE,THE_METHOD_NAME);


        //------------------------------------------------------------------------------
        //  GetBoundData :adding property
        //          <wsdl:message name="GetBoundDataSoapIn"> 
        //          <wsdl:part name="parameters" element="tns:GetBoundData"/> 
        //          </wsdl:message> 
        //  GetBoundData has two params:
        //      <s:element minOccurs="0" maxOccurs="1" name="Bound" type="s:string"/>
        //      <s:element minOccurs="0" maxOccurs="1" name="Zoom" type="s:string"/>
        //
        //--------------------------------------------------------------------------

        //--------------
        //  GetBoundData
        //--------------
        PropertyInfo pi = new PropertyInfo();
        pi.setName("GetBoundData");
        pi.setValue(Whatever_value_your_supposed_to_put);// these values are "Bound" And "Zoom" , they're supposed to be gotten in your app somewhere
        pi.setType(GetBoundData.class);
        sobj.addProperty(pi);

        //------------------------------
        //  START BUILDING SOAP ENVELOPE
        //------------------------------
        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        soapEnvelope.setOutputSoapObject(sobj);


        //---------------------------------------------------------------------------------------
        //      MAPPINGS:   
        //---------------------------------------------------------------------------------------

        soapEnvelope.addMapping(YOUR_NAMESPACE, GetBoundData.class.getSimpleName(), GetBoundData.class);

        //---------------------------------------------------------------------------------------
        //      MARSHALLING: 
        //---------------------------------------------------------------------------------------

        Marshal floatMarshal = new MarshalFloat();
        floatMarshal.register(soapEnvelope);


        AndroidHttpTransport aht = new AndroidHttpTransport(YOUR_URL); 


        aht.debug = true;

        try 
        {

            aht.call(YOUR_ACTION, soapEnvelope);

            //Importat Outputs to check how the request/Response looks like.. Check Logcat to find these outputs
            System.out.println("aht requestDump is :"+aht.requestDump);
            System.out.println("aht responseDump is :"+aht.responseDump);


            return soapEnvelope.getResponse();

        } 
        catch (Exception e) 
        {

            e.printStackTrace();
            return "Exception: " + e.getMessage()+"  message IS :" +e.getMessage()+"  localizedmessage is :"+e.getLocalizedMessage();
        }
    }
    catch(Exception ex)
    {
        ex.printStackTrace();
        return "Exception: " + ex.getMessage();
    }
    }
}

因此​​,检查LogCat中看到的请求和响应的形状,你会看到,如果你有获得响应,并解析它使用它,我不知道你的反应会是,但对我来说这是多维数组,所以我不得不用java功能解析它。
为:

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:

<wsdl:message name="GetBoundDataSoapOut"> 
<wsdl:part name="parameters" element="tns:GetBoundDataResponse"/> 
</wsdl:message> 

这只是告诉你的Web服务发送回一个响应。

this just tells you the web service sends back a response.

这篇关于机器人的SOAPFault错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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