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

 

 

posted @ Thursday, July 06, 2006 3:16 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 3 and type the answer here:
 

Live Comment Preview:

 
«December»
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910