3
[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/">&lt;message loginstatus="OK" userid="1" /&gt;</string>

Actual Format:

<message loginstatus="OK" userid="1" />

What i have to do.

2
  • Actual Format i need is:<message loginstatus="OK" userid="1" /> Commented Jun 22, 2011 at 14:38
  • but i getting value like this:&gtmessage loginstatus="OK" userid="1" /&gt Commented Jun 22, 2011 at 14:39

1 Answer 1

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

1 Comment

Finally i have fond the soln..frustrating ... i didnt get any response from editors .... really frustrating :(

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.