微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 调用WCF引用类型变量

我对C#完全不熟悉.
我有一种服务方法

//actual method
    public DataTable LoadDownLoadTablesData(string strBusinessUnit,string strExecutive,string strTableName,ref string strDate,string strTerritoryCode,string strUField1,string strUField2,string strUFeild3)
    {            
        DataTable ds = new DataTable();
        try 
            {
                XontPDAServiceDAL vu = new XontPDAServiceDAL();
                if (vu.validateExecutive(strBusinessUnit,strExecutive) == true)
                {
                    DownloadFetchBLL wmd = new DownloadFetchBLL();
                    strDate = DateTime.Now.ToString();
                    ds = wmd.LoadDownLoadTableData(strBusinessUnit,strExecutive,strTableName,strTerritoryCode,strUField1,strUField2,strUFeild3);
                }
                else
                {
                    throw new FaultException("Executive Not Active in the system.");
                }
        }
        catch (FaultException) { }
        catch (Exception ex)
        {
            throw new FaultException("Database Server is Not Responding." + ex.Message);
        }

        return ds;
    }

    //Converting datatable to String type
    public string LoadDownLoadTablesDataJson(string strBusinessUnit,string strUFeild3)
    {
        DataTable dtDownloadJson = new DataTable();
        dtDownloadJson = this.LoadDownLoadTablesData(strBusinessUnit,ref strDate,strUFeild3);
        return this.ConverTabletoJson(dtDownloadJson);
    }


    //Converting table to json
    public String ConverTabletoJson(DataTable dtDownloadJson)
    {
        string[] StrDc = new string[dtDownloadJson.Columns.Count];
        string HeadStr = string.Empty;

     //   if (dtDownloadJson.Columns.Count > 0)
      //  {

            for (int i = 0; i < dtDownloadJson.Columns.Count; i++)
            {

                StrDc[i] = dtDownloadJson.Columns[i].Caption;
                HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
            }
            if (HeadStr.Length > 0)
            {
                HeadStr = HeadStr.Substring(0,HeadStr.Length - 1);
                StringBuilder Sb = new StringBuilder();
                Sb.Append("{\"" + dtDownloadJson.TableName + "\" : [");

                for (int i = 0; i < dtDownloadJson.Rows.Count; i++)
                {

                    string TempStr = HeadStr;
                    Sb.Append("{");

                    for (int j = 0; j < dtDownloadJson.Columns.Count; j++)
                    {
                        TempStr = TempStr.Replace(dtDownloadJson.Columns[j] + j.ToString() + "¾",dtDownloadJson.Rows[i][j].ToString());
                    }

                    Sb.Append(TempStr + "},");
                }

                Sb = new StringBuilder(Sb.ToString().Substring(0,Sb.ToString().Length - 1));
                Sb.Append("]}");
                return Sb.ToString();
            }else
            {
                return "0";
            }
       // }else{
       //     return "0";
       // }
    }

这个LoadDownLoadTablesData()引用变量就在那里.

我必须从Android调用此LoadDownLoadTablesDataJson(….),

我这样打电话;

// ksoap2 calling wcf
public SoapPrimitive soapPrimitiveData(String method_name1,String soap_action1,String NAMESPACE,String APPURL,String tablename ) throws IOException,XmlPullParserException {

    SoapPrimitive responses = null;
    SoapObject request = new SoapObject(NAMESPACE,method_name1); // set up

    request.addProperty("strBusinessUnit","HEMA");
    request.addProperty("strExec","4515");
    request.addProperty("strTableName","RD.AlternativeProductHeader");
    // after login we will get these fields value
    request.addProperty("strDate","2000-04-29");
    request.addProperty("TerritoryCode","KAND");

    request.addProperty("strUField1","");
    request.addProperty("strUField2","");
    request.addProperty("strUField3","");


    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); // put all required data into a soap// envelope
    envelope.dotNet = true;
    envelope.setoutputSoapObject(request);
    AndroidHttpTransport httpTransport = new AndroidHttpTransport(APPURL);
    httpTransport.debug = true;
    try {
        httpTransport.call(soap_action1,envelope);
        responses = (SoapPrimitive) envelope.getResponse();

        Log.w("log_tag","@@@@ 218 @@@@" + responses);
    } catch (Exception e) {
        e.printstacktrace();
    }
    return responses;
}

这总是返回“0”.但是当我通过虚拟测试C#site时,它会返回一些结果.
看到

String da1 = "2000-04-29";
        String s = client.LoadDownLoadTablesDataJson("HEMA","4515","RD.AlternativeProductHeader",ref da1,"KAND","","");
        Label1.Text = s;

输出是:

{"Table1" : [{"TableName" : "Loaddistributor","Description" : "distributor ","MandatoryFlag" : "1","Status" : "","Priority" : "0"},{"TableName" : "LoadPrice","Description" : "Price ","Priority" : "0"}]}

我混淆了我们想要如何使用Android传递引用类型?

请帮我..

提前致谢.

解决方法

应该有这样的request.addProperty(“strExecutive”,“4515”);
不是request.addProperty(“strExe”,“4515”);

我应该是服务参数名称.不能给出不同的名字

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐