Note that there are some explanatory texts on larger screens.

plurals
  1. POweb service return anonymous object from method
    primarykey
    data
    text
    <p>I have a simple web service which grabs data from database, and i want to return this data as dataset,string,XML. But the web service xml is not getting what type i returned. The question is, is it possible to return as object and webservice XML to display correct tag. at the moment it displays this tag anytype instead of string for example.</p> <p>here is the method</p> <pre><code> [WebMethod] public Object serviceForPostcode(String postCode, String type) { /** * * create dataset to store query * convert dataset to required return type * create types for returned object * * **/ SqlDataAdapter adapter = new SqlDataAdapter(); SqlCommand cmd = new SqlCommand(); SqlConnection conn = new SqlConnection(dbConnection()); /** * * -- types-- * **/ XmlDocument xmlD = new XmlDocument(); StringWriter sw = new StringWriter(); DataSet dataSet = new DataSet(); /** * * **/ // connection and query string string dbQuery = "SELECT id, address1, address2, address3, address4, address5, post_code, country FROM paf WHERE (post_code = @postCode)"; try { cmd.Parameters.Add(new SqlParameter("@postcode",SqlDbType.NChar, 10)).Value = postCode.ToUpper(); cmd.CommandText = (dbQuery); cmd.CommandType = CommandType.Text; cmd.Connection = conn; adapter.SelectCommand = cmd; adapter.Fill(dataSet,"post codes"); } catch(Exception e) { System.Web.HttpContext.Current.Response.Write(e.Message); } finally { //close database connection conn.Close(); } if (type.Equals("xml", StringComparison.InvariantCultureIgnoreCase)) { return dataSet.GetXml(); } else if (type.Equals("string", StringComparison.InvariantCultureIgnoreCase)) { dataSet.WriteXml(sw); return sw.ToString(); } else if(type.Equals("dataset",StringComparison.InvariantCultureIgnoreCase)) { return ""; } return "error"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload