从.NET调用Java / Axis Web服务:在“返回null”的问题 [英] Invoking a Java/AXIS Web Service from .NET: the ‘return null’ issue

查看:250
本文介绍了从.NET调用Java / Axis Web服务:在“返回null”的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻求通过所有谷歌,计算器等等这一问题。
而且我发现了很多相关答案给它,而不是真正解决问题。

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.

我从.NET客户端消耗Axis服务,但回报总是空,不管我送什么参数,总是为null。

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.

所以我开始看,我试着从 SOAPUI 消费它,和它的工作!

So i started to look, and I tried to consume it from the SOAPUI, and it worked!.

所以,我首先想到的是,.NET做得不对,我找啊找,我发现有一些问题的命名空间。

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.

相关岗位这里

所以在此之后,我试图通过消费服务引用,Web引用的服务,创建具有WSDL.EXE代理(它的建立pretty好!),寻找所有的命名空间,但所有lokked不错。我做了一些修改,以它来命名空间,但没有。

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>

(我从SOAPUI本示例)。

(I got this example from the SOAPUI).

相关文章是这里

我也试过<一个href=\"http://stackoverflow.com/questions/1000578/axis2-always-receives-null-parameters-even-if-soap-request-is-sent-correctly\">this.

和接到了<一个又一个可能的麻烦href=\"http://stackoverflow.com/questions/3157763/java-webservice-returning-null-object-to-a-net-client\">here以命名为项,你可以在上面提到的WebServiceResponse看到一个数组的列出的项目,它们列出这样。所以一切都在我看来,从C#中的反序列化的问题。而看我发现了一个半解决这一切。

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.

现实情况是,实际上.NET得到的回应pretty好,所有它具有与反序列化的步骤问题也许以上(多个命名空间,数组,数组名称类似于项项提到的所有posibles原因)。

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").

<一个href=\"http://www.$c$cproject.com/KB/webservices/Java_WS_NET.aspx\">http://www.$c$cproject.com/KB/webservices/Java_WS_NET.aspx

我在代理这样overrided方法:

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!

因此​​,所有的操作系​​统在这之后我不知道是否有修补程序,服务包,有人发现了我如何正确DESEREALIZE提供WebResponse的解决方案或任何东西。或如何正确食用该轴的服务,我觉得这个最好的形式给出仅仅是序列化响应正确重写方法,因为它似乎是.NET的一个bug,我认为这与烦恼,因为一切都阵列有一个项目就可以了。

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.

我真的真的是preciate任何帮助!

I would really really apreciate any help!.

再次感谢!

推荐答案

最后,我解决了这个问题,我的一个朋友帮我,显然有与WSDL和命名空间的问题。 C#中产生的代理问题。不知道这是一个C#问题或轴问题。但希望这个答案可以帮助别人。
看看对WebService的方法所有的命名空间。 C#产生这样的方法。

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]));
        }

不过在WSDL有这样的事情。

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>

看那&LT;元素名称=PolizaTYPE =tns2:Poliza/&GT; 它是指 tns2 命名空间
它说的xmlns:tns2 =htt​​p://www.example.org/PolizasBanorteSchema

因此​​,通过.NET生成的代理是错误的它必须是这样

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")]

改变了code和一切线工作就像一个魅力
所以,在一个轴服务中使用数组和diferent命名空间时要小心,你可能有一些问题,产生一个C#客户端。

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.

<一个href=\"http://www.primordial$c$c.com/blog/post/invoking-javaaxis-web-service-net-return-null-issue\">This帖子是正确的:)

这篇关于从.NET调用Java / Axis Web服务:在“返回null”的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆