1

VS 2019 VB.NET and c#

I have a web service that calls another web service. The provider web service returns an array of objects. The consumer web service tries to assign the results of the call to a variable and throws an error:

Hexadecimal value 0x00 is a invalid character, line 1, position nnnnn

Note I do not convert the results to or from xml, the 'system' is doing that.

I checked the data and while complex it is fine. I found through trial and error that if I remove a single field that happens to be set to Nothing it works (there are hundreds of fields and many are nothing). I can see nothing special about the field I removed. So it sounds buggy.

I was thinking it might be a unicode issue so I added a globalization entry to the provider web service web.config:

<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>

Which had no effect.

So I have an array of objects (I simplified it to a count of 1, still get the error) that I am trying to return and somewhere between return statement in the provider web service and the assignment of the results to a variable in the consumer web service I'm getting bad xml.

I suppose I could convert it to xml myself, ensuring it is valid, and serve that, but it seems like it should work as is.

Any ideas on how I can track this down?

ADDENDUM

Should have made this a bit more clear. I'm returning an array of user defined objects from a web method, so the data is serialized into a XML SOAP response. If I use postman to look at the response the soap xml response is valid, however when a remote service calls the web method I see this error. So first I'm not sure where the error is being introduced...it does not look like the web method is at fault, postman can call it and get valid xml. But my other program, that happens to be a web service as well, presumably gets bad xml from the request.

kpg
  • 589
  • 6
  • 28

1 Answers1

1

0x0 is the NUL character and is not permitted in XML.

You cannot resolve this problem by changing the character encoding.

Your options:

  1. Fix the provider web service that is sending not-well-formed XML. (This is vastly preferred.)
  2. Attempt to repair the broken responses prior to processing it as XML. (You may have more control to change your end, but in the long run, pushing back on the service provider to fix their broken service will be best for all parties.)

See also:

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I wrote both parts...the thing is I'm not encoding the response into xml, .net is, I assume. I'm just returning an array of objects from a web method. – kpg Oct 02 '20 at 20:58
  • Ok, but it's unlikely that .NET is introducing a `0x0` independent of the data you give it. The library call you make on the service provider side ideally should reject any data it cannot legally add to XML, but perhaps it's imperfect. Since you control the service provider code, focus on filtering the bad data ahead of the .NET library call. – kjhughes Oct 02 '20 at 21:18
  • I agree. Problem is there is no bad data that I can find. If I change my query to not return one date column that is set to nothing it works fine. There are many other date columns set to nothing, they serialize as sql min date. – kpg Oct 02 '20 at 21:50
  • There was indeed a questionable value in the xml. '' The error message gave the character position in the xml, so from postman I got the raw xml went to that position and there it was. What threw me off was the postman xml rendered fine with that value in it so I assumed it was okay. thx. – kpg Oct 03 '20 at 10:22