[ScriptMethod(UseHttpGet = true)]
[WebMethod]
public string sampleTest()
{
string name = "";
name = System.Web.HttpContext.Current.Request.QueryString["name"];
StringBuilder sb = new StringBuilder();
sb.Append("<message>");
sb.Append("<categoryname =" + name + "/>");
sb.Append("</message>");
return sb.ToString();
}
Invoking method :
StringBuilder sb = new StringBuilder();
byte[] buf = new byte[8192];
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/mylytica/apibridge.asmx/sampleTest?name=Shankar");
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
Stream resStream = response.GetResponseStream();
string tempString = null;
int count = 0;
do
{
count = resStream.Read(buf, 0, buf.Length);
if (count != 0)
{
tempString = Encoding.ASCII.GetString(buf, 0, count);
sb.Append(tempString);
}
}
while (count > 0);
Literal1.Text = sb.ToString();
Literal value contains:
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/"><message loginstatus="OK" userid="1" /></string>
Actual Format:
<message loginstatus="OK" userid="1" />
What i have to do.
[ScriptMethod(UseHttpGet = true)]
[WebMethod]
public XmlDocument login(string username, string password)
{
XmlDocument oXmlDoc = new XmlDocument();
XmlNode oXmlmessage = oXmlDoc.CreateNode(XmlNodeType.Element, "message", "");
XmlAttribute oxmllogin = oXmlDoc.CreateAttribute("loginstatus");
oxmllogin.InnerText = "OK";
XmlAttribute oXmluserid = oXmlDoc.CreateAttribute("userid");
oXmluserid.InnerText = iRegID.ToString();
oXmlmessage.Attributes.Append(oxmllogin);
oXmlmessage.Attributes.Append(oXmluserid);
oXmlDoc.AppendChild(oXmlmessage);
return oXmlDoc;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With