4

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;
2
  • Can you show your code too. Commented Dec 24, 2015 at 9:19
  • I experienced the same issue. There was an empty property in our response that was not shown in the wsdl we received which caused an incorrect ordering. Commented Oct 28, 2020 at 14:15

2 Answers 2

6

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, it works. But what is the Order parameter?
It's the order of the field in the XML response. It's needed for deserialization. The way it was, it's expected to return <cityId>1</cityId><cityCode>123</cityCode>, but, in fact, it was returning <cityCode>123</cityCode><cityId>1</cityId>, hence you had to switch the orders between the two fields.
1

I am experiencing the same behavior.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.