开发者

Java Webservice returning null object to a .net client

Can any one figure out my problem is...

I'm calling a webmethod of a Java Webservice (Axis 1.4) from a .Net client. That method returns a Map object, and if i call it from an Axis client works fine, but in my c# code it´s always null.

That's the WSDL:

<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:http.service.enlaces.portlet.ext.com" xmlns:intf="urn:http.service.enlaces.portlet.ext.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://model.enlaces.portlet.ext.com" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:http.service.enlaces.portlet.ext.com">

<wsdl:types>

<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.apache.org/xml-soap">
<import namespace="urn:http.service.enlaces.portlet.ext.com"/>
<import namespace="http://model.enlaces.portlet.ext.com"/>
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="mapItem">
   <sequence>
 <element name="key" nillable="true" type="xsd:anyType"/>
 <element name="value" nillable="true" type="xsd:anyType"/>
   </sequence>
</complexType>
<complexType name="Map">
   <sequence>
   <element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>
   </sequence>
</complexType>   
</schema>
 </wsdl:types>

<wsdl:message name="getFoldersAndBookmarksRequest" />
<wsdl:message name="getFoldersAndBookmarksResponse">
    <wsdl:part name="getFoldersAndBookmarksReturn" type="apachesoap:Map" />
</wsdl:message>

<wsdl:portType name="BookmarksEntryServiceSoap">
<wsdl:operation name="getFoldersAndBookmarks">
      <wsdl:input name="getFoldersAndBookmarksRequest"  message="intf:getFoldersAndBookmarksRequest" />
      <wsdl:output name="getFoldersAndBookmarksResponse" message="intf:getFoldersAndBookmarksResponse" />
    </wsdl:operation>
  </wsdl:portType>

<wsdl:binding name="Portlet_Bookmarks_BookmarksEntryServiceSoapBinding" type="intf:BookmarksEntryServiceSoap">
    <wsdlsoap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc" />
  <wsdl:operation name开发者_如何学编程="getFoldersAndBookmarks">
      <wsdlsoap:operation soapAction="" />
      <wsdl:input name="getFoldersAndBookmarksRequest">
        <wsdlsoap:body use="encoded" namespace="urn:http.service.enlaces.portlet.ext.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:input>
      <wsdl:output name="getFoldersAndBookmarksResponse">
        <wsdlsoap:body use="encoded" namespace="urn:http.service.enlaces.portlet.ext.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
      </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

and my c# auto-generated code:

[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:http.service.enlaces.portlet.ext.com", ResponseNamespace="urn:http.service.enlaces.portlet.ext.com")]
[return: System.Xml.Serialization.SoapElementAttribute("getFoldersAndBookmarksReturn")]
public Map getFoldersAndBookmarks() {
    object[] results = this.Invoke("getFoldersAndBookmarks", new object[0]);
    return ((Map)(results[0]));
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.3082")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.SoapTypeAttribute(Namespace="http://xml.apache.org/xml-soap")]
public partial class Map {

    private mapItem[] itemField;

    /// <comentarios/>
    public mapItem[] item {
        get {
            return this.itemField;
        }
        set {
            this.itemField = value;
        }
    }
}

I,ve seen everywhere unfortunately, i don't find the solution. Please, there are anyone what knows it?


I've faced the same problem a while ago. This happens when you try to get an array of elements through an axis webservice with a .net client.

The problem is "name=item" part of this line :

<element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>

Try changing in that particular line "item" to "mapItem". Try one of these :

<element maxOccurs="unbounded" minOccurs="0" name="mapItem" type="apachesoap:mapItem"/>

or

<element maxOccurs="unbounded" minOccurs="0" name="key" type="apachesoap:mapItem"/>

or

<element maxOccurs="unbounded" minOccurs="0" name="value" type="apachesoap:mapItem"/>


So it very late to help you but I recently was running into the same problem.

Firstly I am using Eclipse to create a web service. The problem for me was that the wsdd generated was using the 'document/literal(wrapped)' style. Changing that to 'RPC' fixed the issue. No more nulls.

So maybe if you change your encoding to RPC that might fix your issue too.


And this is why web services generated from code are almost never interoperable :)

One good way of working around this is to make the wsdl first, and define a nice clear little bit of XSD, that should map nicely into both .Net and java. An alternative is something other than axis 1.4 (yech, the pain) for the server if you have any control over that.

Finally, try massaging the signatures in the java code, try replacing List with MapItem[], or vice versa, make sure you don't have Map anywhere in a return object or a parameter.

Reviewing your generated wsdl again, I'd say this is probably because of the xsd:anyType for the key/value part of the mapItem.

I think that's what is generated by axis if you have a java Object in a parameter. Trust me, you don't want that. Make it a string, or a complex type, or an Integer, but an Object can only imply open ended xml (xsd:anyType) and not many clients no how to parse that.


I faced that, and I had to change WSDL file so:

<wsdlsoap:body use="encoded" ... 

to

<wsdlsoap:body use="literal" ... 

Only to perform the proxy generation.


I faced same issue. My solution is to remove the Namespace in auto-generated function. This is my function:

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://www.service-now.com/incident/getRecords", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Bare)]
[return: System.Xml.Serialization.XmlArrayAttribute("getRecordsResponse", Namespace = "")]
[return: System.Xml.Serialization.XmlArrayItemAttribute("getRecordsResult", Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
public getRecordsResponseGetRecordsResult[] getRecords([System.Xml.Serialization.XmlElementAttribute("getRecords", Namespace = "http://www.service-now.com/incident")] getRecords getRecords1)
{
    object[] results = this.Invoke("getRecords", new object[] {
                getRecords1});
    return ((getRecordsResponseGetRecordsResult[])(results[0]));
}

I removed the Namespace in this line. Bacause when I test the web service via SoapUI, I realized that the response object has no namespace. But auto-generated code has namespace.

[return: System.Xml.Serialization.XmlArrayAttribute("getRecordsResponse", Namespace = "")]

SoapUI Response was as following:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <getRecordsResponse>
         <getRecordsResult>
            <active>0</active>
         </getRecordsResult>
      </getRecordsResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜