4

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)

p.campbell
  • 98,673
  • 67
  • 256
  • 322
  • I found this other question http://stackoverflow.com/questions/4606196/any-tool-to-generate-web-service-proxy-for-net-1-1 , It could help, if there where a good answer. – Guilherme de Jesus Santos Nov 07 '11 at 22:43
  • 1
    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)`. – L.B Nov 07 '11 at 22:45
  • Cool. @L.B We did it. We changed the Reference.cs, Everything that was nillable and wasn't a string we changed to string and treated. And works very well. Thank you. Put your comment as a answer, that I'll make as the better asnwer. Save us a lot of work. Thanks. – Guilherme de Jesus Santos Nov 07 '11 at 23:15

4 Answers4

3

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.

slfan
  • 8,950
  • 115
  • 65
  • 78
2

You could write an intermediate service in .net 2 that shims the service. In other words, you write a service with the same interface, just change the nullable fields to something else, then in the service you call the real service, massage the results, then return them to your 1.1 client.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
2

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)

L.B
  • 114,136
  • 19
  • 178
  • 224
1

When doing stuff in .NET 1.x there's only one way - the hard way (So sue me Lexus) Check out http://msdn.microsoft.com/en-us/magazine/cc188761.aspx And combine it with XSLT (available in 1.x IIRC) to rewrite the definition to fit the deserializer.

stefan
  • 2,886
  • 21
  • 27