Android使用WCF,该特定方法返回DataTable

时间:2011-07-06 12:10:21

标签: android wcf ksoap

我是这个网站的新手& Android,如有任何错误请指出我。我的问题在于肥皂反应,

这是我的Android代码:

    public static final String APPURL = "http://192.168.1.213:7986/XontService";    
    private static final String METHOD_NAME = "LoadDownLoadTables";
    private static final String NAMESPACE = "http://tempuri.org/"; 
    private static String SOAP_ACTION = "http://tempuri.org/IXontPDAService/LoadDownLoadTables";
   try {
         response = soap(METHOD_NAME, SOAP_ACTION, NAMESPACE, APPURL);
         Log.w("log_tag","*********" + response.getProperty(0).toString());

    } catch (IOException e) {
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        e.printStackTrace();
    }

   // ksoap2 calling wcf
public SoapObject soap(String METHOD_NAME, String SOAP_ACTION, String NAMESPACE, String URL) throws IOException, XmlPullParserException {

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up request
    request.addProperty("strExec", "7437");
    request.addProperty("strBusinessUnit", "HHHHH");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); //put all required data into a soap envelope
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);  
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);  
    httpTransport.debug = true;  

    try{
        Log.w("log_tag", " ===========" +SOAP_ACTION.toString() );
        Log.w("Log_cat" ,"*********" + envelope.toString());
        httpTransport.call(SOAP_ACTION, envelope);
    //  Log.d("resBundle", String.valueOf(resBundle)); 
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    SoapObject responses = (SoapObject)envelope.getResponse();
    return responses;


 }

   // response processing
public String[] getStringArrayResponse(SoapObject node, Vector<String> strings) {
    boolean isFirstCall = false;
    if (strings == null) {
        isFirstCall = true;
        strings = new Vector<String>();
    }
    int count = response.getPropertyCount();

    for (int i = 0; i < count; i++) {
        Object obj1 = node.getProperty(i);
        if (obj1 instanceof SoapObject) {
            if (((SoapObject)obj1).getPropertyCount() > 0) {
                getStringArrayResponse((SoapObject)obj1, strings);
            }
        } else if (obj1 instanceof SoapPrimitive) {
            strings.add(((SoapPrimitive)obj1).toString());
        }
    }

    // only make this for the original caller
    if (isFirstCall) {
        return (String[])strings.toArray(new String[strings.size()]);
    }
    return null;
}

这是C#方法:

    public DataTable LoadDownLoadTables(string strExec, string strBusinessUnit)
    {
        DataTable dtDownload = new DataTable();
        try
        {
            XontPDAServiceDAL vu = new XontPDAServiceDAL();

            if (vu.validateExecutive(strBusinessUnit, strExec) == true)
            {
                DownloadFetchBLL wmd = new DownloadFetchBLL();
                dtDownload = wmd.LoadDownLoadTable(strBusinessUnit, strExec);
            }
            else
            {
                throw new FaultException("Executive Not Active in the system.");
            }
        }
        catch (FaultException) { }
        catch (Exception ex)
        {
            throw new FaultException("Database Server is Not Responding.");
        }
        return dtDownload;
    }

这是我的WSDl

  <wsdl:definitions name="XontPDAService" targetNamespace="http://tempuri.org/">
  <wsdl:types>    
     <xsd:schema targetNamespace="http://tempuri.org/Imports"><xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd0" namespace="http://tempuri.org/"/>
     <xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd1" namespace="http://schemas.microsoft.com/2003/10/Serialization/"/>
     <xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd2" namespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
    <xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd3" namespace="http://schemas.datacontract.org/2004/07/System.Data"/>
     <xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd4" namespace="http://schemas.datacontract.org/2004/07/XONT.Common.Data.PDAServiceBLL"/>
    <xsd:import schemaLocation="http://192.168.1.213:7986/XontService?xsd=xsd5"/></xsd:schema>
 </wsdl:types>
   ------
   ------
 <wsdl:operation name="LoadDownLoadTables">
    <soap:operation soapAction="http://tempuri.org/IXontPDAService/LoadDownLoadTables" style="document"/><wsdl:input>
     <soap:body use="literal"/></wsdl:input>
    <wsdl:output><soap:body use="literal"/></wsdl:output>
</wsdl:operation>

和架构文件是:

      <xs:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/System.Data" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/System.Data">
     <xs:element name="DataTable" nillable="true">
      <xs:complexType>
        <xs:annotation>
            <xs:appinfo>
                  <ActualType Name="DataTable" Namespace="http://schemas.datacontract.org/2004/07/System.Data" xmlns="http://schemas.microsoft.com/2003/10/Serialization/" /> 
            </xs:appinfo>
        </xs:annotation>
        <xs:sequence>
    <xs:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" /> 
    <xs:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" /> 
  </xs:sequence>
 </xs:complexType>
 </xs:element>
 </xs:schema>

我收到以下消息:          的 ANYTYPE {元素= anyType的{的complexType = {anyType的选择= {anyType的元素= anyType的{的complexType = {anyType的序列= {anyType的元素= anyType的{};元素= anyType的{};元素= anyType的{};元素= anyType的{};元素= anyType的{}; }; }; }; }; }; }; }

请帮帮我..

2 个答案:

答案 0 :(得分:1)

您是否可以控制您的WCF服务(=可以更改它)吗?如果是,则更改您的服务以返回表示数据表中行的自定义类的数组/列表,并在服务操作中从数据表中填充这些实例。

DataTableDataSet不是可互操作解决方案的不错选择。您传递的消息看起来更像是XSD的某些“反序列化”(因为DataTable可以将其描述作为其序列化数据的一部分进行传输,因此可能会这样做。)

答案 1 :(得分:0)

你必须检查返回类型asp .net数据表然后检查返回newDataSet或DocumentElement ...如果没有返回那些东西然后检查web服务 public static String authentication(String username,String password)     {         String success = null;         ArrayList list = new ArrayList();         SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_Login);         PropertyInfo propertyInfo = new PropertyInfo();         propertyInfo.setName(&#34;用户名&#34);         propertyInfo.setValue(用户名);         propertyInfo.setType(String.class);         request.addProperty(的PropertyInfo,用户名);

    PropertyInfo propertyInfo1 = new PropertyInfo();
    propertyInfo1.setName("password");
    propertyInfo1.setValue(password);
    propertyInfo1.setType(String.class);
    request.addProperty(propertyInfo1,password);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;

    envelope.setOutputSoapObject(request);


    SoapObject result = null;

    HttpTransportSE htse = new HttpTransportSE(SOAP_ADDRESS);
    try {

        htse.debug = true;
        htse.call(SOAP_ACTIONLogin, envelope);
        result =(SoapObject) envelope.bodyIn;

    } catch (IOException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e){
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    SoapObject root = (SoapObject) result.getProperty(0);
    SoapObject s_deals = (SoapObject) root.getProperty("diffgram");
    SoapObject s_deals_1 = (SoapObject)s_deals.getProperty("NewDataSet");

    for (int i = 0; i < s_deals_1.getPropertyCount(); i++) {

        Object property = s_deals_1.getProperty(i);
        if (property instanceof SoapObject) {

            SoapObject category_list = (SoapObject)property;

            String EmpID = category_list.getProperty("EmpId").toString();
            String UserName = category_list.getProperty("MstEmpName").toString();
            LoginModel lm=new LoginModel();
            lm.setEmpID(EmpID);
            lm.setUserName(UserName);
            list.add(lm);
            if(list!=null)
            {
                success="valid";
            }
            Log.e("name",UserName);
            Log.e("EmpID",EmpID);


        }   

    }
相关问题