Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com

Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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 on Thursday, July 6, 2006 3:16 PM ASP.NET | Back to top


Comments on this post: Unreadable characters in Web Services string parameter can cause HTTP status 400: Bad Request

# re: Unreadable characters in Web Services string parameter can cause HTTP status 400: Bad Request
Requesting 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?
Left by Krunal on May 10, 2010 5:19 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net