Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 1.1 consuming a webservice with nullable types, what to do?

I need to consume a WebService with .NET 1.1. The problem is that the webService return Null Values, and .NET 1.1 doesn't work with Nullable types.

A piece of the WebService Schema

 <xs:element name="SomeDate" type="xs:dateTime" nillable="true" />
 <xs:element name="Email" type="xs:string" nillable="true" />

How could you consume it? Wich approach would I use to solve this puzzle?

I can't even Invoke the webService. .Net 1.1 try to parse the null values, and crash.

When we try to invoke the WebService, it give us the exception below:

Input string was not in a correct format.

Exception Details: System.FormatException: Input string was not in a correct format.

Line 75: [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://mysite.com/Clientes/ConsultaCliente", RequestNamespace="http://mysite.com/Clientes/", ResponseNamespace="http://mysite.com/Clientes/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]

Line 76: public Clientes ConsultaCliente(ParametrosConsultaClientes parametros) {

Line 77: object[] results = this.Invoke("ConsultaCliente", new object[] {

Line 78: parametros});

[FormatException: Input string was not in a correct format.]

System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +0

System.Int32.Parse(String s, NumberStyles style, IFormatProvider provider) +37

System.Xml.XmlConvert.ToInt32(String s)

like image 224
Guilherme de Jesus Santos Avatar asked Feb 23 '23 11:02

Guilherme de Jesus Santos


2 Answers

You could wrap your DateTime class (of any other value type that has to be nullable) into a NullableDateTime class (as a reference type). It's not so nice as a generic type but should work even in .NET 1.1.

I didn't test it but I just found a Nullable Type Library on Source Forge.

like image 133
slfan Avatar answered Feb 25 '23 01:02

slfan


Maybe you can add some extra controls to the proxy class VS or wsdl.exe automatically generates (C:\Projetos\PortalIO\Fontes\DotNet\Source\PortalIO\Web References\wsCentralClientes\Reference.cs)

like image 23
L.B Avatar answered Feb 25 '23 00:02

L.B