0

I have developed a web service for storing data in database from mobile application using wcf post method. Following is the method I am using to save data in database.

public void AddBook3(string Ans3, string Ans4, string Ans5, string Ans6, string Ans7, string Ans8, string Ans9, string Ans10, string Ans11, string Ans12,string customername)
{        
    server = "localhost";
    database = "Feed";
    uid = "root";
    string message;
    // password = "password";
    mySqlConnection = new MySql.Data.MySqlClient.MySqlConnection();

    mySqlConnection.ConnectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";";
    mySqlConnection.Open();

    MySqlCommand cmd = new MySqlCommand("insert into answers(ans3,ans4,ans5,ans6,ans7,ans8,ans9,ans10,ans11,ans12,customername)                                             values(@ans3,@ans4,@ans5,@ans6,@ans7,@ans8,@ans9,@ans10,@ans11,@ans12,@customername)", mySqlConnection);

    cmd.Parameters.AddWithValue("@ans3",  Ans3);
    cmd.Parameters.AddWithValue("@ans4", Ans4);
    cmd.Parameters.AddWithValue("@ans5", Ans5);
    cmd.Parameters.AddWithValue("@ans6", Ans6);
    cmd.Parameters.AddWithValue("@ans7", Ans7);
    cmd.Parameters.AddWithValue("@ans8", Ans8);
    cmd.Parameters.AddWithValue("@ans9", Ans9);
    cmd.Parameters.AddWithValue("@ans10", Ans10);
    cmd.Parameters.AddWithValue("@ans11", Ans11);
    cmd.Parameters.AddWithValue("@ans12", Ans12);
    cmd.Parameters.AddWithValue("@customername", customername);
    int result = cmd.ExecuteNonQuery();
    if (result == 1)
    {
        // message = userinfo.Id + "user info inserteddd";
    }
    else
    {
        //   message = userinfo.Id + "information not insertedd";
    }
}

Following is operation contract:

  [OperationContract]
        [WebInvoke(UriTemplate = "AddBook3/{Ans3}/{Ans4}/{Ans5}/{Ans6}/{Ans7}/{Ans8}/{Ans9}/{Ans10}/{Ans11}/{Ans12}/{customername}")]
        void AddBook3(string Ans3, string Ans4, string Ans5, string Ans6, string Ans7, string Ans8, string Ans9, string Ans10, string Ans11, string Ans12, string customername);

And my parameters to this url is as below:

http://localhost:80/IBookService.svc/AddBook/Morning$(7am-11am),/Set$Top$Box$or$Chatri$Connection/3/3/3424324,234234,24234,23423,/Diya$Aur$Baati,Sapne$Suhane$Ladakpan$Ke,Jodha$Akbar,Tumhari$Pakhi,Ek$Nayi$Pehaan,Yeh$Rishsta$Kya$Kehlata$Hai,Crime$Patrol,Taarak$Mehta,Sasural$Simar$Ka,---,---,---,---,---,---,---,---,---,/Suraj-Sandhya,Jodha-Akbar,Gopi-Ahem,Ishita-$-$Raman,Rachana$-$Gunjan,Akshara$-$Naitik,/234234/rtertert/pnme

When I pass long string to url it won't work. When I pass just short texts then it works fine!! Why so?

Robert
  • 10,403
  • 14
  • 67
  • 117
pravin
  • 454
  • 1
  • 6
  • 19

1 Answers1

1

I would change this to something like:

public void AddBook3(List<string> answers ,string customername)

or create a class like:

public class CustomerAnswers
{
  public string CustomerName {get;set;}
  public string Answer1 {get;set;}
  public string Answer2 {get;set;}
  ....
}

and pass this class to the service.

public void AddBook3(CustomerAnswers customerAnswers)

I think the issue you are getting is the limitation on URL length, which I think is ~2000 characters. See this SO post What is the maximum length of a URL in different browsers?

EDIT: Based on Objective-c comment

I'm not familiar with Objective-c, but I'm assuming you'd create a JSON object that represents the CustomerAnswers class, and pass this...there's an example question here Pass object as a parameter to wcf service in Objective C on iOS.

Community
  • 1
  • 1
Christian Phillips
  • 18,399
  • 8
  • 53
  • 82