简体   繁体   English

ASP.NET中的多行文本框呈现问题

[英]Multiline textbox rendering issue in asp.net

I have developed a client page for wcf service. 我已经为wcf服务开发了一个客户端页面。 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. 基本上,我的页面有一个按钮和两个文本框,一个用于从xml文件加载请求xml,另一个用于显示响应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. 问题是,从wcf服务获得任何错误之后,我的请求xml文本框将忽略所有xml节点,它仅显示带有偶数空格的节点值。

this is working in one machine it is not working in another machine. 这是在一台机器上工作,而不是在另一台机器上工作。 two machines are windows xp os, ie 7. 两台机器是Windows XP OS,即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. request xml文本框内的request xml <node> test </ node> <node1> test; </ node1>。 after error from wcf display as " test test". wcf错误后显示为“测试测试”。

i have no clue for this problem. 我对这个问题一无所知。

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. 如果您确实使用WCF,则不必使用HttpWebRequest和HttpWebResponse手动调用URL,也不必手动解析XML。 You should add the service to the Service References, see: 您应该将该服务添加到“服务引用”中,请参阅:

http://msdn.microsoft.com/en-us/library/bb628652.aspx 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: 如果不是WCF,而是常规的SOAP Web服务,您仍然可以将其添加为Web参考,请参见:

http://msdn.microsoft.com/en-us/library/bb628649.aspx 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. 至于文本显示,您的catch处理程序中什么也没有,所以我不确定文本框将在何处获取任何值。 You must be setting it somewhere outside the code snippet you have provided. 您必须将其设置在您提供的代码段之外的某个地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM