Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSDL Web Service returns empty array from C#

I am using a web service with this address: https://api.n11.com/ws/CityService.wsdl

The service has a method 'GetCities'. You can test it with http://wsdlbrowser.com/

The problem is when I get Cities from C#, it returns an array of 81 elements but 'cityId' and 'cityName' gets null.

enter image description here

Please help!

My code is shown below:

        GetCitiesRequest request = new GetCitiesRequest();
        CityServicePortClient port = new CityServicePortClient();

        GetCitiesResponse getCitiesResponse = port.GetCities(request);

        var list = getCitiesResponse.cities;
like image 857
Kemal Duran Avatar asked Mar 13 '23 19:03

Kemal Duran


2 Answers

Got it!!!

Visual Studio is messing up the Order parameter on XmlElementAttribute, so, in your References.cs file change the following:

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public long cityId 

to

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public long cityId 

and

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)]
public string cityCode

to

[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)]
public string cityCode
like image 104
Anderson Pimentel Avatar answered Mar 19 '23 02:03

Anderson Pimentel


I am experiencing the same behavior.

My assumption is, that the service: https://api.n11.com/ws/CityService.wsdl is not returning a value.

like image 38
Daniel Avatar answered Mar 19 '23 02:03

Daniel