Unreadable characters in Web Services string parameter can cause HTTP status 400: Bad Request

I have a web service that sends USMARC record as string. USMARC uses unreadable characters Chr(29)/Chr(30)/Chr(31) as separators.

 MS web services XMLSerializer doesn't encode these characters and causes
System.Net.WebException: "The request failed with HTTP status 400: Bad Request".
Interesting to note that the error not happened if test the operation using the HTTP POST protocol or if a string is incorporated into Dataset record.
I am using simple Encode/Decode functions to workaround the issue.

TODO: It would be better to use standard encoding technique,described in MSDN and implemented in XmlTextWriter.WriteString Method   “Character values 0x-0x1F are encoded as numeric character entities � through , except for the white space characters 0x9, 0x10, and 0x13.“

    'there is complimentary function before SOAP send to encode the characters
    'Can't send the special characters in soap 'caused  "HTTP status 400-Bad Request" 
    Public Shared Function USMARCSpecialCharactersEncode(ByVal str As String) As String

        str = Replace(str, Chr(30), "{30}")

        str = Replace(str, Chr(31), "{31}")

        str = Replace(str, Chr(29), "{29}")

        Return str

    End Function

    'there is complimentary function after SOAP receive to decode the characters

    Public Shared Function USMARCSpecialCharactersDecode(ByVal str As String) As String

        str = Replace(str, "{29}", Chr(29))

        str = Replace(str, "{30}", Chr(30))

        str = Replace(str, "{31}", Chr(31))

        Return str

    End Function

 

 

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted @ Thursday, July 06, 2006 3:16 PM
Print

Comments on this entry:

# re: Unreadable characters in Web Services string parameter can cause HTTP status 400: Bad Request

Left by Krunal at 5/10/2010 5:19 AM
Gravatar
What if I have to send hex character I need to pass in Web service request.?

I got same HTTP 400 Bad Request Error. What is the fix for it?

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910