I am getting the following error in my Xamarin Forms app but I don't know what the problem is:
System.InvalidOperationException: There is an error in XML document.
items xmlns=''> was not expected
I have a basic XML file that I have added as an embedded resource:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<id>1</id>
<name>a name</name>
<address>an address</address>
<postcode>a postcode</postcode>
</item>
<item>
<id>2</id>
<name>name 2</name>
<address>address 2</address>
<postcode>postcode 2</postcode>
</item>
<item>
<id>3</id>
<name>name 3</name>
<address>address 3</address>
<postcode>postcode 3</postcode>
</item>
</items>
I have the following method to read the XML file:
public static List<Item> GetItemList()
{
var assembly = typeof(MyNewPage).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream("MyNewApp.allitems.xml");
List<Item> itemsFullList;
using (var reader = new System.IO.StreamReader(stream))
{
var serializer = new XmlSerializer(typeof(List<Item>));
itemsFullList = (List<Item>)serializer.Deserialize(reader);
}
return itemsFullList;
}
I also have a standard class to represent each item:
public class Item
{
public Item()
{
}
public string name { get; set; }
public string address { get; set; }
public string postcode { get; set; }
}
I don't know why I am getting the error as from what I can see, the XML document is formatted just fine. I am using this article as a guide but I am having no luck: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/files/
Anyone know what I am doing wrong here?
Thanks.
That class structure will not deserialize to a list of Item, it will deserialize to a single object that has a property of type Item[].
You will probably want to change class and property names to make more sense, but this is how Visual Studio generates the class structure based on your xml (Edit > Paste Special)
void Main()
{
string xml = #"<?xml version=""1.0"" encoding=""UTF-8""?>
<items>
<item>
<id>1</id>
<name>a name</name>
<address>an address</address>
<postcode>a postcode</postcode>
</item>
<item>
<id>2</id>
<name>name 2</name>
<address>address 2</address>
<postcode>postcode 2</postcode>
</item>
<item>
<id>3</id>
<name>name 3</name>
<address>address 3</address>
<postcode>postcode 3</postcode>
</item>
</items>";
using (MemoryStream ms = new MemoryStream())
{
XDocument.Parse(xml).Save(ms);
ms.Position = 0;
using (var reader = new System.IO.StreamReader(ms))
{
var serializer = new XmlSerializer(typeof(items));
var itemsFullList = (items)serializer.Deserialize(reader);
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(ElementName = "items", Namespace = "", IsNullable = false)]
public partial class items
{
private itemsItem[] itemField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("item")]
public itemsItem[] item
{
get
{
return this.itemField;
}
set
{
this.itemField = value;
}
}
}
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class itemsItem
{
private byte idField;
private string nameField;
private string addressField;
private string postcodeField;
/// <remarks/>
public byte id
{
get
{
return this.idField;
}
set
{
this.idField = value;
}
}
/// <remarks/>
public string name
{
get
{
return this.nameField;
}
set
{
this.nameField = value;
}
}
/// <remarks/>
public string address
{
get
{
return this.addressField;
}
set
{
this.addressField = value;
}
}
/// <remarks/>
public string postcode
{
get
{
return this.postcodeField;
}
set
{
this.postcodeField = value;
}
}
}
Related
Trying to create a web api using c# .net which will take following input
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUser xmlns="http://tempuri.org/">
<UserRecorder>
<COMPANY>string</COMPANY>
<PASSWORD>string</PASSWORD>
<USER>string</USER>
<UserRecord>
<item>
<ST>1</ST>
<LT>1</LT>
<TNO>ABC</TNO>
</item>
</UserRecord>
</UserRecorder>
</GetUser>
</soap:Body>
</soap:Envelope>
and should return the following output in XML
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetUserResponse xmlns="http://tempuri.org/">
<UserRecorder.Response>
<Company>string</Company>
<UserRecord.Response>
<item>
<ST>int</ST>
<LT>int</LT>
<TNo>string</TNo>
<ADate>string</ADate>
<ATime>string</ATime>
<LAT>string</LAT>
<LON>string</LON>
</item>
</UserRecord.Response>
</UserRecorder.Response>
</GetUserResponse>
</soap12:Body>
</soap12:Envelope>
==== WHAT I DID TILL NOW ===
Input step done as you can see below XML input generated from API link
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUser xmlns="http://tempuri.org/">
<UserRecorder>
<COMPANY>string</COMPANY>
<PASSWORD>string</PASSWORD>
<USER>string</USER>
<UserRecord>
<item>
<ST>int</ST>
<LT>int</LT>
<TNO>string</TNO>
</item>
</UserRecord>
</UserRecorder>
</GetUser>
</soap:Body>
</soap:Envelope>
Now I am facing issue to generating same response as shared above. My response coming as follow: by using POSTMAN
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetUserResponse xmlns="http://tempuri.org/">
<GetUserResult><?xml version="1.0" encoding="utf-8"?><UserRecorder xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><Company>TW</Company><UserRecord><item><ST>1</ST><LT>1</LT><TNo>4582</TNo><ADate>20210415</ADate><ATime>20:00:00</ATime><LAT>65.25</LAT><LON>108.24</LON></item></UserRecord></UserRecorder></GetUserResult>
</GetUserResponse>
</soap:Body>
</soap:Envelope>
My Code snippet as follows:
//CUserResponse class
public class CUserResponse
{
public class UserRecorder
{
private string company;
public string Company
{
get { return company; }
set { company = value; }
}
private UserRecord eTA_TRACK;
public UserRecord UserRecord
{
get { return eTA_TRACK; }
set { eTA_TRACK = value; }
}
}
public class UserRecord
{
private Item roots;
public Item item
{
get { return roots; }
set { roots = value; }
}
}
public class Item
{
int sALES_TYPE;
int lOCATION_TYPE;
string tANK_LORRY_NO = string.Empty;
string aLERT_DATE = string.Empty;
string aLERT_TIME = string.Empty;
string lOCATION_COORDINATES_LAT = string.Empty;
string lOCATION_COORDINATES_LON = string.Empty;
public int ST
{
get { return sALES_TYPE; }
set { sALES_TYPE = value; }
}
public int LT
{
get { return lOCATION_TYPE; }
set { lOCATION_TYPE = value; }
}
public string TNo
{
get { return tANK_LORRY_NO; }
set { tANK_LORRY_NO = value; }
}
public string ADate
{
get { return aLERT_DATE; }
set { aLERT_DATE = value; }
}
public string ATime
{
get { return aLERT_TIME; }
set { aLERT_TIME = value; }
}
public string LAT
{
get { return lOCATION_COORDINATES_LAT; }
set { lOCATION_COORDINATES_LAT = value; }
}
public string LON
{
get { return lOCATION_COORDINATES_LON; }
set { lOCATION_COORDINATES_LON = value; }
}
}
}
/// End of CUserResponse class
And asmx code is below:
//asmx code snippet
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class KECommWebService : System.Web.Services.WebService
{
#region API
public class Item
{
int sALES_TYPE;
int lOCATION_TYPE;
string tANK_LORRY_NO = string.Empty;
public int ST
{
get { return sALES_TYPE; }
set { sALES_TYPE = value; }
}
public int LT
{
get { return lOCATION_TYPE; }
set { lOCATION_TYPE = value; }
}
public string TNO
{
get { return tANK_LORRY_NO; }
set { tANK_LORRY_NO = value; }
}
}
public class UserRecord
{
private Item roots;
public Item item
{
get { return roots; }
set { roots = value; }
}
}
public class UserRecorder
{
private string company;
private string password;
private string user;
public string COMPANY
{
get { return company; }
set { company = value; }
}
public string PASSWORD
{
get { return password; }
set { password = value; }
}
public string USER
{
get { return user; }
set { user = value; }
}
private UserRecord eTA_TRACK;
public UserRecord UserRecord
{
get { return eTA_TRACK; }
set { eTA_TRACK = value; }
}
}
[WebMethod]
public string GetUser(UserRecorder UserRecorder)
{
CUserResponse.UserRecorder cETAResponse = new CUserResponse.UserRecorder();
cETAResponse.Company = "TW";
CUserResponse.UserRecord eTA_TRACKResponse = new CUserResponse.UserRecord();
CUserResponse.Item itemresponse = new CUserResponse.Item();
itemresponse.ST = 1;
itemresponse.LT = 1;
itemresponse.ADate = "20210415";
itemresponse.ATime = "20:00:00";
itemresponse.LAT = "65.25";
itemresponse.LON = "108.24";
itemresponse.TNo = "4582";
eTA_TRACKResponse.item = itemresponse;
cETAResponse.UserRecord = eTA_TRACKResponse;
Type t = cETAResponse.GetType();
var xml = "";
using (StringWriter sww = new Utf8StringWriter())
{
using (XmlWriter writer = XmlWriter.Create(sww))
{
var ns = new XmlSerializerNamespaces();
// add empty namespace
//ns.Add("", "");
XmlSerializer xsSubmit = new XmlSerializer(t);
xsSubmit.Serialize(writer, cETAResponse, ns);
xml = sww.ToString(); // Your XML
}
}
return xml;
}
public class Utf8StringWriter : StringWriter
{
public override Encoding Encoding => Encoding.UTF8;
}
#endregion
}
//END of asmx code snippet
Pl guide...
There is a WSDL scheme for SOAP in OTRS, unfortunately with an automaton (connecting links), it does not work, because Sharp considers the file to be incorrect. for normal operation, you must obtain the following:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="http://www.otrs.org/TicketConnector/">
<soapenv:Header/>
<soapenv:Body>
<SessionCreate>
<tic:UserLogin>ULogin</tic:UserLogin>
<tic:CustomerUserLogin>CustUser</tic:CustomerUserLogin>
<tic:Password>ULPassword</tic:Password>
</SessionCreate>
</soapenv:Body>
</soapenv:Envelope>
I tried through System.Runtime.Serialization.Formatters.Soap as follows:
[Serializable]
public partial class Envelope
{
/// <remarks/>
public object Header { get; set; }
/// <remarks/>
public EnvelopeBody Body { get; set; }
}
[Serializable]
public partial class EnvelopeBody
{
public SessionCreate SessionCreate { get; set; }
}
[Serializable]
[System.Xml.Serialization.SoapType(IncludeInSchema =true, Namespace = "")]
public partial class SessionCreate
{
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string UserLogin { get; set; }
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string CustomerUserLogin { get; set; }
/// <remarks/>
[System.Xml.Serialization.SoapElement("http://www.otrs.org/TicketConnector/")]
public string Password { get; set; }
}
class TEST
{
void GetSoap()
{
var model = new SessionCreate
{
UserLogin ="ULogin",
CustomerUserLogin="CustUser",
Password="ULPassword"
};
var en = new Envelope
{
Body = new EnvelopeBody
{
SessionCreate = model
}
};
SoapFormatter formatter = new SoapFormatter();
var ms = new MemoryStream();
formatter.Serialize(ms, en);
Console.WriteLine(StreamToString(ms));
}
string StreamToString(Stream stream)
{
stream.Position = 0;
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
}
As a result, it displays the following:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Envelope id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_Header_x003E_k__BackingField xsi:type="xsd:anyType" xsi:null="1"/>
<_x003C_Body_x003E_k__BackingField href="#ref-3"/>
</a1:Envelope>
<a1:EnvelopeBody id="ref-3" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_SessionCreate_x003E_k__BackingField href="#ref-4"/>
</a1:EnvelopeBody>
<a1:SessionCreate id="ref-4" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/OTRS.Request/OTRS%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<_x003C_UserLogin_x003E_k__BackingField id="ref-5">ULogin</_x003C_UserLogin_x003E_k__BackingField>
<_x003C_CustomerUserLogin_x003E_k__BackingField id="ref-6">CustUser</_x003C_CustomerUserLogin_x003E_k__BackingField>
<_x003C_Password_x003E_k__BackingField id="ref-7">ULPassword</_x003C_Password_x003E_k__BackingField>
</a1:SessionCreate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
The question arises, how to do it normally, and what am I doing wrong?
I've been trying to de serialise an XML file into a list, but whatever I do, the list ends up with a count of 0.
I've been searching Stack like I normally do, tried all kinds of things, but am at my wit's end. What's going wrong here?
My XML:
<?xml version="1.0" encoding="utf-8"?>
<lijst>
<lijst_item>
<id>1</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>2</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>3</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
</lijst>
Lijst_item object:
[XmlType("Lijst_item")]
public class Lijst_item
{
[XmlAttribute("id", DataType = "int")]
public int ID { get; set; }
[XmlElement("naam")]
public string Name { get; set; }
[XmlElement("archived", DataType ="boolean")]
public bool isArchived { get; set; }
public Lijst_item()
{
}
public Lijst_item(int id, string name, bool archived)
{
this.ID = id;
this.Name = name;
this.isArchived = archived;
}
}
Code used to de serialise:
using (StreamReader sr = new StreamReader(sFile))
{
XmlSerializer deserializer = new XmlSerializer(typeof(List<Lijst_item>), new XmlRootAttribute("lijst"));
var Test = (List<Lijst_item>)deserializer.Deserialize(sr);
}
Convert xml to List by Deserialize in c#
Did not help me: Exactly what am I doing wrong? Is my XML malformed? My object? Can I for some reason not use a List?
Try this...
Usings...
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
Classes...(created using your XML at http://xmltocsharp.azurewebsites.net/)
[XmlRoot(ElementName = "lijst_item")]
public class Lijst_item
{
[XmlElement(ElementName = "id")]
public string Id { get; set; }
[XmlElement(ElementName = "naam")]
public string Naam { get; set; }
[XmlElement(ElementName = "archived")]
public string Archived { get; set; }
}
[XmlRoot(ElementName = "lijst")]
public class Lijst
{
[XmlElement(ElementName = "lijst_item")]
public List<Lijst_item> Lijst_item { get; set; }
}
Code...
string strXML = #"<?xml version=""1.0"" encoding=""utf-8""?>
<lijst>
<lijst_item>
<id>1</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>2</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
<lijst_item>
<id>3</id>
<naam>NAME REDACTED</naam>
<archived>false</archived>
</lijst_item>
</lijst>";
byte[] bufXML = ASCIIEncoding.UTF8.GetBytes(strXML);
MemoryStream ms1 = new MemoryStream(bufXML);
// Deserialize to object
XmlSerializer serializer = new XmlSerializer(typeof(Lijst));
try
{
using (XmlReader reader = new XmlTextReader(ms1))
{
Lijst deserializedXML = (Lijst)serializer.Deserialize(reader);
}// put a break point here and mouse-over Label1Text and Label2Text ….
}
catch (Exception ex)
{
throw;
}
I want to create object that after serialize to xml should looks like:
<List>
<Map>
<Entry Key="1" Value="ASD" />
</Map>
<Map>
<Entry Key="2" Value="DFE" />
</Map>
</List>
Instead of this my result is:
<List>
<Map>
<Entry Key="1" Value="ASD" />
<Entry Key="2" Value="DFE" />
</Map>
</List>
My piece of code:
public partial class List {
private Map[] mapField;
[System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[System.Xml.Serialization.XmlArrayItemAttribute("Entry", typeof(Map), Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=false)]
public Map[] Map {
get {
return this.mapField;
}
set {
this.mapField = value;
}
}
public partial class MapTypeEntry
{
private string keyField;
private string valueField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Key {
get {
return this.keyField;
}
set {
this.keyField = value;
}
}
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
What I'm doing wrong?
I think I did typo somewhere, but I can't find where.
Maybe there is problem with xml attributes?
Maytbe this shouldn't be xmlArray item?
EDIT:
Complete code:
var mapEntry = new Map();
mapEntry.Key = "1";
mapEntry.Value = "ASD";
mapEntries.Add(mapEntry);
mapEntry = new Map();
mapEntry.Key = "2";
mapEntry.Value = "DFE";
mapEntries.Add(mapEntry);
var exampleType = new List();
List.Map = mapEntries.ToArray();
You need to change model as I implemented below (just simple exmple).
namespace TestApp
{
using System;
using System.IO;
using System.Xml.Schema;
using System.Xml.Serialization;
class Program
{
static void Main(string[] args)
{
var list = new List
{
Map = new[]
{
new Entry {EntryItem = new EntryItem {Key = "1", Value = "ASD"}},
new Entry {EntryItem = new EntryItem {Key = "2", Value = "DFE"}}
}
};
Console.Write(Serialize(list));
Console.ReadKey();
}
private static string Serialize(List list)
{
var xmlSerializer = new XmlSerializer(typeof (List));
var stringWriter = new StringWriter();
xmlSerializer.Serialize(stringWriter, list);
return stringWriter.ToString();
}
}
[XmlRoot(ElementName = "Root")]
public partial class List
{
[XmlArray(ElementName = "List")]
[XmlArrayItem("Map", typeof (Entry), Form = XmlSchemaForm.Unqualified, IsNullable = false)]
public Entry[] Map { get; set; }
}
public class Entry
{
[XmlElement("Entry")]
public EntryItem EntryItem { get; set; }
}
public class EntryItem
{
[XmlAttribute]
public string Key { get; set; }
[XmlAttribute]
public string Value { get; set; }
}
}
So it creates XML:
<?xml version="1.0" encoding="utf-16"?>
<Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<List>
<Map>
<Entry Key="1" Value="ASD" />
</Map>
<Map>
<Entry Key="2" Value="DFE" />
</Map>
</List>
</Root>
Here's what your class List should look :
public partial class List
{
private Map[] mapField;
[XmlElement("Map", typeof(Map), Form = System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable = false)]
public Map[] Map
{
get
{
return this.mapField;
}
set
{
this.mapField = value;
}
}
[...]
}
And for your Map class
public class Map
{
[XmlElement("Entry")]
public KVPair Item { get; set; }
}
And the one I called KVPair
public class KVPair
{
[XmlAttribute()]
public string Key { get; set; }
[XmlAttribute()]
public string Value { get; set; }
}
the Xml Produced is :
<?xml version="1.0"?>
<List xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Map>
<Entry Key="1" Value="ASD" />
</Map>
<Map>
<Entry Key="2" Value="DFE" />
</Map>
</List>
You should avoid using class name frequently used such as List. If you want to call it with a different name, use XmlRootAttribute to keep "List" for your xml file.
I am new to SOAP Webservice. Please suggest me how to achieve following XML
I'm trying to generate C# that creates a fragment of XML like this.
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<querySeatResponse xmlns="xxx">
<querySeatResult>
<querySeat_status code="int" msg="string">
<details>
<detail seat_no="string" available="string" />
<detail seat_no="string" available="string" />
</details>
</querySeat_status>
</querySeatResult>
</querySeatResponse>
</soap:Body>
</soap:Envelope>
But I am getting following Output :
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<querySeatResponse xmlns="xxx">
<querySeatResult>
<querySeat_status code="int" msg="string">
<details>
<detail xsi:nil="true" />
<detail xsi:nil="true" />
</details>
</querySeat_status>
</querySeatResult>
</querySeatResponse>
</soap:Body>
</soap:Envelope>
My Source Code as follows :
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class abc : System.Web.Services.WebService
{
[WebMethod]
[SoapDocumentMethod("xxx", RequestNamespace = "xxx", ResponseNamespace = "xxx", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public querySeat_Main querySeat([XmlAttribute] string signature, string operator_code, string route_id, string trip_no, string depart_date, string counter_from, string counter_to, string bus_type)
{
querySeat_Main main = new querySeat_Main();
querySeat_status status = new querySeat_status();
querySeat_status.detail detail = new querySeat_status.detail();
status.code = 0;
status.msg = "success";
main.querySeat_status = status;
return main;
}
}
[Serializable]
[GeneratedCode("System.Xml", "xxxx")]
[XmlType(Namespace = "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
public class querySeat_Main
{
querySeat_status status;
public querySeat_Main()
{
}
public querySeat_status querySeat_status { get { return status; } set { status = value; } }
}
[Serializable]
[GeneratedCode("System.Xml", "xxx")]
[XmlType(Namespace = "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlRoot("querySeat_status", Namespace = "xxx")]
public class querySeat_status
{
int Code;
string Msg;
public querySeat_status() { }
[XmlAttribute]
public int code { get { return Code; } set { Code = value; } }
[XmlAttribute]
public string msg { get { return Msg; } set { Msg = value; } }
[XmlArray("details")]
[XmlArrayItem("detail")]
public List<detail> details = new List<detail>();
[Serializable]
[GeneratedCode("System.Xml", "xxx")]
[DebuggerStepThrough]
[DesignerCategory("code")]
[XmlRoot("querySeat_status", Namespace = "xxx")]
public class detail
{
string seat;
string avail;
public detail() { }
[XmlAttribute]
public string seat_no { get { return seat; } set { seat = value; } }
[XmlAttribute]
public string available { get { return avail; } set { avail = value; } }
}
}
As mentioned by Alex, looks like you don't initialize your details, you can try:
public querySeat_Main querySeat([XmlAttribute] string signature, string operator_code, string route_id, string trip_no, string depart_date, string counter_from, string counter_to, string bus_type)
{
querySeat_Main main = new querySeat_Main();
querySeat_status status = new querySeat_status();
querySeat_status.detail detail = new querySeat_status.detail();
detail.available = "no";
detail.seat_no = "7";
status.code = 0;
status.details = new List<querySeat_status.detail>();
status.details.Add(detail);
status.msg = "success";
main.querySeat_status = status;
return main;
}