Invoking a Java/AXIS Web Service from .NET: the ‘return null’ issue

会有一股神秘感。 提交于 2019-12-03 06:17:17

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 :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!