locked
How to handle special characters in webservice code

    Question

  • I need to pass desc as parameter to my webservice which can accept 3000 characters only
    There is a chance that desc may conatin even specail characters so for that i am doing encoding for the desc.
    Although the desc has 3000 characters as i am encoding so total number of characters are getting increased to more than 3000(because space is a single length character but after encoding it is %20 that means now it is 3 character length)

    var baseFilter = new HttpBaseProtocolFilter();
                baseFilter.CacheControl.ReadBehavior = Windows.Web.Http.Filters.HttpCacheReadBehavior.MostRecent;
                baseFilter.CacheControl.WriteBehavior = Windows.Web.Http.Filters.HttpCacheWriteBehavior.NoCache;
                using (var httpClient = new System.Net.Http.HttpClient())
                {
                    try
                    {

                      var data = new List<KeyValuePair<string, string>>()

                        {                            
                        new  KeyValuePair<string, string>("desc",Uri.EscapeDataString(desc))


                    };

                          var response = await httpClient.PostAsync("www.exampleservice.com/meth?", new       System.Net.Http.FormUrlEncodedContent(data));
                        response.EnsureSuccessStatusCode();


                      

    Monday, October 20, 2014 7:01 AM

Answers

  • Hi Sandeep,

    Your server only accept 3000 characters?

    How about use GZipStream Class ?

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 21, 2014 7:12 AM
    Moderator