Vetrivel mp
Vetrivel mp

Reputation: 1224

Multiline textbox rendering issue in asp.net

I have developed a client page for wcf service. basically my page has one button and two textboxes one is for loading request xml from xml file, and another one is displaying response xml. Problem is that after any error got from wcf service my request xml textbox ignores all xml nodes it just displays node values with even spaces.

this is working in one machine it is not working in another machine. two machines are windows xp os, ie 7.

<TextBox ID="requesttextbox" runat="server" TextMode="MultiLine" Width="470px"
                Height="300px" Wrap="false/>

button click code something like this

System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
xmlDoc.XmlResolver = null;
xmlDoc.LoadXml(requesttextbox.Text);
HttpWebRequest objHttpWebRequest = null;
HttpWebResponse objHttpWebResponse = null;

string strFinalRequestXML = xmlDoc.OuterXml;

objHttpWebRequest = (HttpWebRequest)WebRequest.Create("RequestURL");
objHttpWebRequest.Method = "POST";
objHttpWebRequest.Accept = "xml";
objHttpWebRequest.ContentType = "application/xml; charset=utf-8";
objHttpWebRequest.Timeout = 300000;
objHttpWebRequest.ContentLength = strFinalRequestXML.Length;
System.IO.StreamWriter sw = new System.IO.StreamWriter  (objHttpWebRequest.GetRequestStream());
sw.Write(strFinalRequestXML);
sw.Close();

try
{
    objHttpWebResponse = (HttpWebResponse)objHttpWebRequest.GetResponse();
    Stream streamResponseText = objHttpWebResponse.GetResponseStream();
    StreamReader srFinalResponseText = new StreamReader(streamResponseText, Encoding.UTF8);
    txtResponse.Text = string.Empty;

    // formattin xml string to as xml nodes to display in textbox
    System.Xml.Linq.XElement element = System.Xml.Linq.XElement.Parse(srFinalResponseText.ReadToEnd());
    txtResponse.Text = element.ToString();

    strStatusCode = objHttpWebResponse.StatusCode.GetHashCode().ToString();

}
catch (WebException objWebException)
{
}

For example:

request xml <node>test</node> <node1>test;</node1> inside request xml text box. after error from wcf display as " test test".

i have no clue for this problem.

Upvotes: 0

Views: 458

Answers (1)

mgnoonan
mgnoonan

Reputation: 7200

If you are truly using WCF, you shouldn't have to manually call the URL using HttpWebRequest and HttpWebResponse, nor should you have to parse the XML by hand. You should add the service to the Service References, see:

http://msdn.microsoft.com/en-us/library/bb628652.aspx

If it is not WCF, but instead a regular SOAP web service, you can still add it as a Web Reference, see:

http://msdn.microsoft.com/en-us/library/bb628649.aspx

Then you can write code that is a little easier:

using (var client = new MyService.MyServiceClient())
{
    string foo;
    foo = client.MyMethod();
}

As for the text display, there is nothing in your catch handler, so I'm not sure where the textbox would be getting any sort of value. You must be setting it somewhere outside the code snippet you have provided.

Upvotes: 1

Related Questions