I've been seeking for this problem through all google, stackoverflow and more. And I found a lot of related answers to it, but not a real solution.
I'm consuming an Axis Service from a .NET Client but the return is always null, no matter what parameters I send, always is null.
So i started to look, and I tried to consume it from the SOAPUI, and it worked!.
So my first thought was, .NET is doing something wrong, and i searched and searched and I found that there are some problems with the namespaces.
Related post here
So after this, I tried to consume the Service via Service Reference, Web Reference, creating a proxy with WSDL.EXE( It was created pretty well!) and looked for all the namespaces, but All lokked good.. I made some changes to it to the namespace but nothing.
Then I found that not just the namespaces are problematics, also the arrays; and in fact the service Returns something like this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<InformacionPolizaResponse xmlns="http://www.openuri.org/">
<ns1:Poliza xmlns:ns1="http://www.example.org/PolizasBanorteSchema">
<ns1:Numero>0036887</ns1:Numero>
<ns1:Serie></ns1:Serie>
<ns1:Ramo>00110</ns1:Ramo>
<ns1:Subramo>00110</ns1:Subramo>
<ns1:Inciso></ns1:Inciso>
<ns1:ClaveAgente>000270</ns1:ClaveAgente>
<ns1:NombreAgente>NOMBRE PENDIENTE</ns1:NombreAgente>
<ns1:NumeroOficina></ns1:NumeroOficina>
<ns1:FechaEmision>2011-02-15</ns1:FechaEmision>
<ns1:FechaInicioVigencia>2011-02-15</ns1:FechaInicioVigencia>
<ns1:FechaFinVigencia>2012-02-15</ns1:FechaFinVigencia>
<ns1:Estatus>03</ns1:Estatus>
<ns1:NombreContratante>CARLOS ZARATE JIMENEZ</ns1:NombreContratante>
<ns1:RfcContratante>ZAJC720213K98</ns1:RfcContratante>
<ns1:Telefono>0449626251463</ns1:Telefono>
<ns1:Moneda>1</ns1:Moneda>
<ns1:FormaPago>003</ns1:FormaPago>
<ns1:PrimaPrimerPago>237.84</ns1:PrimaPrimerPago>
<ns1:PrimaPagoSubsecuente>237.84</ns1:PrimaPagoSubsecuente>
<ns1:PrimaNeta>951.36</ns1:PrimaNeta>
<ns1:FinancPagofraccionado></ns1:FinancPagofraccionado>
<ns1:GastosExpedicion>.00</ns1:GastosExpedicion>
<ns1:IVA></ns1:IVA>
<ns1:PrimaTotal></ns1:PrimaTotal>
<ns1:PolizaOrigen>0036887</ns1:PolizaOrigen>
<ns1:PolizaRenueva>0000000</ns1:PolizaRenueva>
<ns1:Producto></ns1:Producto>
<ns1:Plan></ns1:Plan>
<ns1:Asegurados>
<ns1:item>
<ns1:Nombre>CARLOS ZARATE JIMENEZ</ns1:Nombre>
<ns1:Clave></ns1:Clave>
<ns1:Direccion>
<ns1:Calle></ns1:Calle>
<ns1:Colonia></ns1:Colonia>
<ns1:Poblacion></ns1:Poblacion>
<ns1:Estado></ns1:Estado>
<ns1:CP></ns1:CP>
<ns1:Texto></ns1:Texto>
</ns1:Direccion>
<ns1:FechaNacimiento>1972-02-13</ns1:FechaNacimiento>
<ns1:Sexo>1</ns1:Sexo>
<ns1:Fumador>1</ns1:Fumador>
<ns1:Parentesco>0</ns1:Parentesco>
<ns1:AntiguedadDesde></ns1:AntiguedadDesde>
<ns1:Coberturas>
<ns1:item>
<ns1:Clave>00150</ns1:Clave>
<ns1:Seccion></ns1:Seccion>
<ns1:NombreCobertura>SEGURO DE MUERTE ACCIDENTAL</ns1:NombreCobertura>
<ns1:LimiteMaximo>250,000</ns1:LimiteMaximo>
<ns1:Deducible>.00</ns1:Deducible>
<ns1:Prima>820.00</ns1:Prima>
<ns1:EdadCalculo>039</ns1:EdadCalculo>
<ns1:PlazoSeguro></ns1:PlazoSeguro>
<ns1:PlazoPago></ns1:PlazoPago>
<ns1:SumaAsegurada>250,000</ns1:SumaAsegurada>
<ns1:Coaseguro>.00</ns1:Coaseguro>
</ns1:item>
<ns1:item>
<ns1:Clave>00150</ns1:Clave>
<ns1:Seccion></ns1:Seccion>
<ns1:NombreCobertura>SEGURO DE MUERTE ACCIDENTAL</ns1:NombreCobertura>
<ns1:LimiteMaximo>250,000</ns1:LimiteMaximo>
<ns1:Deducible>.00</ns1:Deducible>
<ns1:Prima>95.00</ns1:Prima>
<ns1:EdadCalculo>039</ns1:EdadCalculo>
<ns1:PlazoSeguro></ns1:PlazoSeguro>
<ns1:PlazoPago></ns1:PlazoPago>
<ns1:SumaAsegurada>250,000</ns1:SumaAsegurada>
<ns1:Coaseguro>.00</ns1:Coaseguro>
</ns1:item>
<ns1:item>
<ns1:Clave>00150</ns1:Clave>
<ns1:Seccion></ns1:Seccion>
<ns1:NombreCobertura>SEGURO DE MUERTE ACCIDENTAL</ns1:NombreCobertura>
<ns1:LimiteMaximo>500</ns1:LimiteMaximo>
<ns1:Deducible>.00</ns1:Deducible>
<ns1:Prima>36.36</ns1:Prima>
<ns1:EdadCalculo>039</ns1:EdadCalculo>
<ns1:PlazoSeguro></ns1:PlazoSeguro>
<ns1:PlazoPago></ns1:PlazoPago>
<ns1:SumaAsegurada>500</ns1:SumaAsegurada>
<ns1:Coaseguro>.00</ns1:Coaseguro>
</ns1:item>
</ns1:Coberturas>
<ns1:Beneficiarios/>
</ns1:item>
</ns1:Asegurados>
<ns1:Incisos/>
<ns1:Recibos>
<ns1:item>
<ns1:NumeroRecibo>5183648</ns1:NumeroRecibo>
<ns1:FechaEmision>2011-02-15</ns1:FechaEmision>
<ns1:FechaEstatus>2011-02-26</ns1:FechaEstatus>
<ns1:FechaPago>2011-02-26</ns1:FechaPago>
<ns1:Estatus>00</ns1:Estatus>
<ns1:DescripcionEstatus>GENERADO</ns1:DescripcionEstatus>
<ns1:Importe>000000275.89</ns1:Importe>
<ns1:Recargos>.00</ns1:Recargos>
<ns1:DerechoPoliza>.00</ns1:DerechoPoliza>
<ns1:FechaInicioVigencia>2011-02-15</ns1:FechaInicioVigencia>
<ns1:FechaFinVigencia>2011-05-15</ns1:FechaFinVigencia>
<ns1:PrimaTotal xsi:nil="true"/>
<ns1:PrimaPagada xsi:nil="true"/>
<ns1:PrimaPendiente xsi:nil="true"/>
</ns1:item>
<ns1:item>
<ns1:NumeroRecibo>5183649</ns1:NumeroRecibo>
<ns1:FechaEmision>2011-02-15</ns1:FechaEmision>
<ns1:FechaEstatus>2011-02-15</ns1:FechaEstatus>
<ns1:FechaPago>1900-00-00</ns1:FechaPago>
<ns1:Estatus>00</ns1:Estatus>
<ns1:DescripcionEstatus>GENERADO</ns1:DescripcionEstatus>
<ns1:Importe>000000275.89</ns1:Importe>
<ns1:Recargos>.00</ns1:Recargos>
<ns1:DerechoPoliza>.00</ns1:DerechoPoliza>
<ns1:FechaInicioVigencia>2011-05-15</ns1:FechaInicioVigencia>
<ns1:FechaFinVigencia>2011-08-15</ns1:FechaFinVigencia>
<ns1:PrimaTotal xsi:nil="true"/>
<ns1:PrimaPagada xsi:nil="true"/>
<ns1:PrimaPendiente xsi:nil="true"/>
</ns1:item>
<ns1:item>
<ns1:NumeroRecibo>5183650</ns1:NumeroRecibo>
<ns1:FechaEmision>2011-02-15</ns1:FechaEmision>
<ns1:FechaEstatus>2011-02-15</ns1:FechaEstatus>
<ns1:FechaPago>1900-00-00</ns1:FechaPago>
<ns1:Estatus>00</ns1:Estatus>
<ns1:DescripcionEstatus>GENERADO</ns1:DescripcionEstatus>
<ns1:Importe>000000275.89</ns1:Importe>
<ns1:Recargos>.00</ns1:Recargos>
<ns1:DerechoPoliza>.00</ns1:DerechoPoliza>
<ns1:FechaInicioVigencia>2011-08-15</ns1:FechaInicioVigencia>
<ns1:FechaFinVigencia>2011-11-15</ns1:FechaFinVigencia>
<ns1:PrimaTotal xsi:nil="true"/>
<ns1:PrimaPagada xsi:nil="true"/>
<ns1:PrimaPendiente xsi:nil="true"/>
</ns1:item>
<ns1:item>
<ns1:NumeroRecibo>5183651</ns1:NumeroRecibo>
<ns1:FechaEmision>2011-02-15</ns1:FechaEmision>
<ns1:FechaEstatus>2011-02-15</ns1:FechaEstatus>
<ns1:FechaPago>1900-00-00</ns1:FechaPago>
<ns1:Estatus>00</ns1:Estatus>
<ns1:DescripcionEstatus>GENERADO</ns1:DescripcionEstatus>
<ns1:Importe>000000275.89</ns1:Importe>
<ns1:Recargos>.00</ns1:Recargos>
<ns1:DerechoPoliza>.00</ns1:DerechoPoliza>
<ns1:FechaInicioVigencia>2011-11-15</ns1:FechaInicioVigencia>
<ns1:FechaFinVigencia>2012-02-15</ns1:FechaFinVigencia>
<ns1:PrimaTotal xsi:nil="true"/>
<ns1:PrimaPagada xsi:nil="true"/>
<ns1:PrimaPendiente xsi:nil="true"/>
</ns1:item>
</ns1:Recibos>
<ns1:Endosos/>
<ns1:Siniestros/>
</ns1:Poliza>
</InformacionPolizaResponse>
</soapenv:Body>
</soapenv:Envelope>
(I got this example from the SOAPUI).
The related post is here
I tried also this.
And got another possible trouble from here with the listed items of an array named as "item", as you can see in the WebServiceResponse mentioned above, they are listed like that. So everything seemed to me that is a deserialization problem from c#. And looking I found a half-solution to all of this.
The reality was that actually .NET get the response pretty good, all that it has is problem with the deserializing step maybe for all the posibles causes mentioned above(multiple namespaces, arrays, array items named like "item").
http://www.codeproject.com/KB/webservices/Java_WS_NET.aspx
I overrided the method in my Proxy like this:
protected override System.Net.WebResponse GetWebResponse(System.Net.WebRequest request)
{
WebResponse wr = base.GetWebResponse(request);
StreamReader sr = new StreamReader(wr.GetResponseStream());
//throw new Exception(sr.ReadToEnd());
return wr ;
}
I thrown the exception to see if the result of the Service was catched and in fact is right there!
So after all os this I dont know if there is a fix, a service pack, someone found a solution or anything of HOW I CAN DESEREALIZE CORRECTLY THE WebResponse. Or how to consume correctly that axis service, I think the best aproach to this is just serialize the response correctly overriding the method, because it seems like a bug of .NET, I think it has troubles with the because everything array has an "item" on it.
Thanks in advance for read this post.
I would really really apreciate any help!.
Thanks again!.
Finally I solved this problem, a friend of mine helped me, apparently there were problems with the WSDL and the namespaces. C# generated the proxy wrong. Don't know if it's a c# problem or axis problem. But hope this answer helps anyone else. Take a look to all the namespaces on the methods of the WebService. C# Generated a method like this.
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.openuri.org/InformacionPoliza", RequestNamespace = "http://www.openuri.org/", ResponseNamespace = "http://www.openuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("Poliza")]
public Poliza InformacionPoliza(CriteriosPoliza CriteriosPoliza)
{
object[] results = this.Invoke("InformacionPoliza", new object[] {
CriteriosPoliza});
return ((Poliza)(results[0]));
}
But in the WSDL had something like this..
<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://www.openuri.org/" xmlns:intf="http://www.openuri.org/" xmlns:tns1="http://www.example.org/PolizasBanorteSchemaCriterios" **xmlns:tns2="http://www.example.org/PolizasBanorteSchema"** xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.openuri.org/">
<!--
WSDL created by Apache Axis version: 1.4 Built on Apr 22, 2006 (06:55:48 PDT)
-->
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.openuri.org/">
<import namespace="http://www.example.org/PolizasBanorteSchema"/>
<import namespace="http://www.example.org/PolizasBanorteSchemaCriterios"/>
<element name="InformacionPoliza">
<complexType>
<sequence>
<element name="CriteriosPoliza" type="tns1:CriteriosPoliza"/>
</sequence>
</complexType>
</element>
<element name="InformacionPolizaResponse">
<complexType>
<sequence>
**<element name="Poliza" type="tns2:Poliza"/>**
</sequence>
</complexType>
</element>
</schema>
Look at the <element name="Poliza" type="tns2:Poliza"/>
it refers to the tns2
namespace
and it says xmlns:tns2="http://www.example.org/PolizasBanorteSchema"
So the generated proxy by .NET was wrong it had to be like this
/// <remarks/>
[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.openuri.org/InformacionPoliza", RequestNamespace = "http://www.openuri.org/", ResponseNamespace = "http://www.openuri.org/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
[return: System.Xml.Serialization.XmlElementAttribute("Poliza", Namespace = "http://www.example.org/PolizasBanorteSchema")]
public Poliza InformacionPoliza(CriteriosPoliza CriteriosPoliza)
{
object[] results = this.Invoke("InformacionPoliza", new object[] {
CriteriosPoliza});
return ((Poliza)(results[0]));
}
The namespace did the magic,
[return: System.Xml.Serialization.XmlElementAttribute("Poliza", Namespace = "http://www.example.org/PolizasBanorteSchema")]
Changed that line of code and everything worked like a charm So, be careful when using arrays and diferent namespaces in an axis service, you may have some problems generating a c# client.
This post was right :)