Question

I'm working on a web service based system which has a Client who encrypts a text using DES algorithm.

When my client sends the encrypted text to a web method on the web service, I catch a

ProtocolException exception saying The remote server returned an unexpected response: (400) Bad Request.

Text before encryption : "Hello"
Text after encryption : "I%�l�*�"

What should I do to solve the issue?

Was it helpful?

Solution

Exception occurred due to special characters in string which is not supported. You can make change in service to accept stream in place of string.

Server side code :

Boolean GetData(Stream fStream)
{
    try 
    {           
    // Read the stream into a byte array

    Byte[] data  = new Byte[32767];
    using (MemoryStream ms = new MemoryStream())
    {
            while(true)
            {
                    Int32 read = stream.Read(data, 0, data.Length);
                    if(read <= 0)
                        return ms.ToArray();
                    ms.Write(data, 0, read);
            }
    }

    // Copy to a string for header parsing
    String content = Encoding.UTF8.GetString(data);

    // do something
    }
    catch (Exception ex)
    {
    throw(ex);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top