本文介绍了如何解析来自.NET Web服务的DiffGram anytype类型响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从.NET Web服务是anytype类型format.I以下响应需要解析这个格式和读取format.I提供诸如RemMessage和INVM_ID数据值我不能够解析这种格式,并得到适当的价值。java的code是..

I am getting the following response from a .net webservice which is of anytype format.I need to parse this format and read the data value like RemMessage and INVM_ID provided in the format.I am not able to parse this format and get appropriate value.The java code is ..

public class WebService {

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        SoapObject request = new SoapObject(NAMESPACE, webMethName);
        androidHttpTransport.debug=true;
        androidHttpTransport.setXmlVersionTag("");
        // Property which holds input parameters
        PropertyInfo sayHelloPI = new PropertyInfo();
        // Set Name
        sayHelloPI.setName("UserId");
        // Set Value
        sayHelloPI.setValue("41");
        // Set dataType
        sayHelloPI.setType(String.class);
        // Add the property to request object
       request.addProperty(sayHelloPI);
        //Set envelope as dotNet
       envelope.dotNet = true;
       envelope.setOutputSoapObject(request);
       try {
            List<GetReminder> reminders = new ArrayList<>();
            androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            // Invoke web service
            androidHttpTransport.call(SOAP_ACTION, envelope);
            // Get the response
            String response=androidHttpTransport.responseDump;
            Log.d("Result --- ", response.toString() );
            SoapObject obj=(SoapObject)envelope.getResponse();
            System.out.println("obj---->" + obj.toString());
         } catch (SocketException e) {
            Log.e("Error :" ,"Error " +e.getMessage());
            //Print error
            e.printStackTrace();
            //Assign error message to resTxt
            resTxt = "Error occured";
        }
        catch (XmlPullParserException e1)
        {
            String resp=androidHttpTransport.responseDump;
            e1.printStackTrace();
            resTxt = "Error occured";
        }
        //Return resTxt to calling object
        return resTxt;
    }
}

这是我返回象下面这样的回应,我需要读取数据的这些PARAMS RemMessage,InvM_Id和我有类似

This is returning me a response like below ,i need to read the data of these params RemMessage ,InvM_Id and i have GetReminder class like

public class GetReminder implements Serializable {
    private String RemMessage;
    private int InvM_Id;
    private int DocType;
    private int PrmR_TypeId;
    private int PrmR_Id;

    public String getRemMessage() {
        return RemMessage;
    }

    public void setRemMessage(String remMessage) {
        RemMessage = remMessage;
    }

    public int getInvM_Id() {
        return InvM_Id;
    }

    public void setInvM_Id(int invM_Id) {
        InvM_Id = invM_Id;
    }

    public int getPrmR_TypeId() {
        return PrmR_TypeId;
    }

    public void setPrmR_TypeId(int prmR_TypeId) {
        PrmR_TypeId = prmR_TypeId;
    }

    public int getDocType() {
        return DocType;
    }

    public void setDocType(int docType) {
        DocType = docType;
    }

    public int getPrmR_Id() {
        return PrmR_Id;
    }

    public void setPrmR_Id(int prmR_Id) {
        PrmR_Id = prmR_Id;
    }

}

响应格式

 anyType {
    schema = anyType {
        element = anyType {
            complexType = anyType {
                choice = anyType {
                    element = anyType {
                        complexType = anyType {
                            sequence = anyType {
                                element = anyType {

                                };
                                element = anyType {

                                };
                                element = anyType {

                                };
                                element = anyType {

                                };
                                element = anyType {

                                };
                            };
                        };
                    };
                };
            };
        };
    };
    diffgram = anyType {
        NewDataSet = anyType {
            Table = anyType {
                RemMessage = ExeedDiscountLimitonInvoicedatedon05 / 03 / 2015forCSHAH,
                from3 - LokhandwalaShowroom;
                InvM_Id = 77693;
                DocType = 3;
                PrmR_TypeId = 3;
                PrmR_Id = 1820;
            };
        };
    };
    }

这仅仅是一个单一的消息格式(RemMessage),我会得到RemMessage的多个条目。

This is just a single message format (RemMessage) ,i will be getting multiple entries of RemMessage.

推荐答案

您已经包括在这篇文章的SOAP响应的XML重新presentation:Parsing用的DiffGram 复杂的SOAP响应。还有我们可能会看到,第一个元素(纲目= {anyType类型...)仅仅是类型的定义,NewDataSet」。所以你需要来解析第二部分,即适用于GetReminder模型的数据。
在code是根据您上次在这里发布http://stackoverflow.com/a/30059614/4114960

You have included XML representation of soap response in this post: Parsing Complex Soap Response with diffgram. And there we may see, that first element ("schema = anyType {...") is only a definition of type "NewDataSet". So You need to parse only second part, that holds data for GetReminder models.The code is under Your last posting here http://stackoverflow.com/a/30059614/4114960

这篇关于如何解析来自.NET Web服务的DiffGram anytype类型响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 11:40