problem with Convert.FromBase64String function

G

Guest

I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?
 
J

Jon Skeet [C# MVP]

scottrm said:
I have a asp.net web service built in c# which is accepting a string
parameter from a vb6 client. The string parameter contains some xml. I am
attempting to convert the string to a byte array using the
Convert.FromBase64String function but get the following error.

Invalid length for a Base-64 char array

The same code works ok if I call it from an asp.net client. In that client I
am just passing the parameter through as a standard string. Any ideas why
the same is not working from the vb6 client?

It sounds like you're not actually getting the same string. Check
whether you're getting a rogue null termination character at the end of
the string.

I suggest you dump out the string in both the working and non-working
versions and compare them *very* carefully. (Compare the lengths
first!). See
http://www.pobox.com/~skeet/csharp/strings.html
for some code you can grab to help you dump the strings out in a useful
way.
 
G

Guest

Thanks for the reply, the strings did seem to be different, by one character,
the string from the vb6 client seemed to have a blank character (U+0020)
where there should have been a + symbol (U+002b). Any ideas on why this is
happening?

Have a good Christmas!
 
G

Guest

Just to clarify on this, in the vb code the string is being declared
correctly with the "+" symbol in it. It is on the transfer of the string into
the c# web service that things seem to be going wrong.
 
J

Jon Skeet [C# MVP]

scottrm said:
Just to clarify on this, in the vb code the string is being declared
correctly with the "+" symbol in it. It is on the transfer of the string into
the c# web service that things seem to be going wrong.

It sounds like you're not decoding a URL parameter correctly - note
that "+" is the URL encoded form of " ".

I suggest you trace at what point the string has a space, and how it's
being transferred. If you're using the normal web service
infrastructure, it should all be dealt with for you though...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top