I write a web service using c# and it going to be consumed in a java application.
Simply I return a Dataset
that has one or more DataTable
in it. Output is in XML format.
Now the consumer need to have the schema of the output table to know the table and field names.
this is the webmethod:
[WebMethod]
public DataSet GetWorkTypes(string UserName, string Password)
{
DataSet ds = new DataSet("CNIS");
try
{
if (User Pass is Correct)
{
SqlDataAdapter adapter = new SqlDataAdapter("some query", "connectionString");
adapter.Fill(ds, "theTable");
return ds;
}
else
{
ds.Tables.Add("theTable");
ds.Tables["theTable"].Columns.Add("Error");
ds.Tables[0].Rows.Add("Wrong User Pass!");
return ds;
}
}
catch (Exception ex)
{
ds.Tables.Add("theTable");
ds.Tables["theTable"].Columns.Add("Error");
ds.Tables[0].Rows.Add(ex.Message);
return ds;
}
}
How do I change my code to do that?
EDIT:
I expect the different output than this:
<?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>
<GetWorkTypesResponse xmlns="http://cnis/">
<GetWorkTypesResult>
<xsd:schema>schema</xsd:schema>xml</GetWorkTypesResult>
</GetWorkTypesResponse>
</soap12:Body>
</soap12:Envelope>
I need something to be more descriptive.
Actually this is the answer to my question that inspired by @John Saunders comment. When the web service consumer is a java client, JQuery or a non-dotNet client, this is not the standard way to pass .NET-specific data type like DataSet
.
So I use the MVC Web API technology to get the job done! It is not necessary to force use MVC , but it gives some good features to generate help and documentation for the web methods.