Formatting exception when calling to web service

C

Chris Hardie

Hi,

I have added a web service reference to my project and am calling out
to a third-party web service. Everything works fine, except in numeric
fields there is sometimes a null value. And I mean a string
representation of null:

<projectId>null</projectId>

When my web service client is doing its magic building records, it
calls out to StringToNumber(), passes in "null", and I get a
formatting exception.

Since I don't control the web service client code, is there a solution
for getting around this?

Thanks,

Chris
 
A

Arne Vajhøj

I have added a web service reference to my project and am calling out
to a third-party web service. Everything works fine, except in numeric
fields there is sometimes a null value. And I mean a string
representation of null:

<projectId>null</projectId>

When my web service client is doing its magic building records, it
calls out to StringToNumber(), passes in "null", and I get a
formatting exception.

Since I don't control the web service client code, is there a solution
for getting around this?

If null is not a legal value, then you should complain to the owner
of the service.

If null is a legal value and you need it as null if it is null,
then you need an int? (or similar) and the if generated stub does
not do that, then you will need to drop the generated stub and
parse the SOAP manually. Extra work that should be avoided
if possible, but it is doable and if that is the only way then
you have to do it.

If null is a legal value but you are OK with it being translated
to some magic value (0 or -1 or whatever), then you can keep
the generated stub, but fix the XML behind the scene.

You setup a BehaviorExtensionElement that create an
IEndpointBehavior that add an IClientMessageInspector.

It is also some work, but it is a supported part of WCF.

Arne
 

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