0

I have made a webservice and some web methods that I call in my android application with ksoap work. One of these methods gets a Farsi string and inserts it into the database but when I back out and check I see only question marks(?) instead of Farsi characters.

web service caller method in my android app with ksoap

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

my web method :

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

setrescomment methode in payamDB class

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; }
    }
racecarjonathan
  • 1,244
  • 1
  • 11
  • 22
Payam
  • 36
  • 5

2 Answers2

0

To view on a Windows machine download the Farsi fonts. Same goes for Android. You are a getting a question mark because your system doesn't know what type of language or font that is.

racecarjonathan
  • 1,244
  • 1
  • 11
  • 22
  • tanx for your attention. but if insert from .net freamwork it's ok but when i call insert methode in webservice from android app it doesent work – Payam Jul 23 '14 at 07:41
  • .NET includes Persian if I'm not mistaken. Android does not. Follow instructions from this site [link](http://www.pedramhayati.com/2011/05/15/persianfarsi-language-for-android/) to get Persian font on your Android device. If my info was helpful please mark my answer as correct. Thank you. – racecarjonathan Jul 23 '14 at 17:38
  • tanx jonathanmpower. but my device already has persian keyboard. with ksoap i can send english text and recive it but if text typed in persian when i rcive it all of character changed to ? – Payam Jul 24 '14 at 06:59
0

Finally I found my answer

We should use N before value that is in UTF-8 encoding in insert query

Like this :

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);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Payam
  • 36
  • 5