【问题标题】:how to send farsi text from android to sql server DB in android with WCF如何使用 WCF 将波斯语文本从 android 发送到 android 中的 sql server DB
【发布时间】:2014-07-22 22:30:46
【问题描述】:

我创建了一个 web 服务和一些 web 方法,我在我的 android 应用程序中调用了 ksoap 工作。 其中一种方法获取波斯语字符串并将其插入数据库,但是当我退出并检查时,我只看到问号(?)而不是波斯语字符。

在我的安卓应用中使用 ksoap 的 web 服务调用方法

        public String sendcomment(String Comment , Float rate)

          {

            String MethodName="SetResComment";
            try {
                SOAP_ACTION = namespace + MethodName;

                //Adding values to request object
                request = new SoapObject(namespace, MethodName);
                //Adding string value to request object
                PropertyInfo P_RSID =new PropertyInfo();
                P_RSID.setName("RSID");
                P_RSID.setValue(staticvar.CurrentRes.getID()); //llllllllll
                P_RSID.setType(String.class);
                request.addProperty(P_RSID);

                PropertyInfo P_UID =new PropertyInfo();
                P_UID.setName("UID");
                P_UID.setValue(staticvar.UID); //llllllllll
                P_UID.setType(String.class);
                request.addProperty(P_UID);

                PropertyInfo P_Name =new PropertyInfo();
                P_Name.setName("Name");
                P_Name.setValue(staticvar.Mame); //llllllllll
                P_Name.setType(String.class);
                request.addProperty(P_Name);

                PropertyInfo P_Comment =new PropertyInfo();
                P_Comment.setName("Comment");
                P_Comment.setValue(Comment); //llllllllll
                P_Comment.setType(String.class);
                request.addProperty(P_Comment);

                PropertyInfo P_Rate =new PropertyInfo();
                P_Rate.setName("Rate");
                P_Rate.setValue(String.valueOf(rate)); //llllllllll
                P_Rate.setType(String.class);
                request.addProperty(P_Rate);




                SetEnvelope();

                try {

                    //SOAP calling webservice
                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    //Got Webservice response
                    String result = envelope.getResponse().toString();

                    return result;

                } catch (Exception e) {
                    // TODO: handle exception
                    return e.toString();
                }
            } catch (Exception e) {
                // TODO: handle exception
                return e.toString();
            }
          }

我的网络方法:

[WebMethod]
    public string SetResComment(string RSID, string UID, string Name, string Comment, string Rate)
    {
        float rt = float.Parse(Rate);
        PayamDB pdb = new PayamDB();
        return pdb.SetResComment(RSID, UID, Name, Comment, rt);
    }

payamDB 类中的setrescomment 方法

public string SetResComment(string RSID,string UID, string Name, string Comment,float Rate)
    {
        try
        {

            SqlCommand command;

            {
                command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "','" + Name + "' , '" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);
                command.Connection.Open();
                int s=command.ExecuteNonQuery();
                command.Connection.Close();
                return s.ToString();
            }


        }
        catch (Exception e) { return "error:"+e.Message; }
    }

【问题讨论】:

    标签: android wcf android-ksoap2 farsi


    【解决方案1】:

    要在 Windows 机器上查看,请下载波斯语字体。安卓也是如此。你是一个问号,因为你的系统不知道那是什么类型的语言或字体。

    【讨论】:

    • 请注意。但是如果从 .net framwork 插入就可以了,但是当我从 android 应用程序在 web 服务中调用 insert 方法时它不起作用
    • 如果我没记错的话,.NET 包括波斯语。安卓没有。按照该站点 link 的说明在您的 Android 设备上获取波斯字体。如果我的信息有帮助,请将我的答案标记为正确。谢谢。
    • tanx jonathanmpower。但我的设备已经有波斯语键盘。使用 ksoap 我可以发送英文文本并接收它,但如果在我接收时输入波斯语文本,所有字符都更改为?
    【解决方案2】:

    终于找到答案了

    我们应该在插入查询中使用 UTF-8 编码的值之前使用N

    像这样:

    command = new SqlCommand("insert into DB_9B1504_daghfood.dbo.T_Res_Comment (ResID,UserID,UserName,Comment,rate,TimeDate) values ('" + RSID + "','" + UID + "', N'" + Name + "' , N'" + Comment + "' , '" + Rate + "' , ' " + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')", connection);
    

    【讨论】:

    • 它实际上是 NOT UTF-8,但是 SQL Server 中的 UCS-2(每个字符总是 2 个字节)...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 2013-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多