我有两个Webapplication Webapplication1和Webapplication2。我在Webapplication1中读取xml数据。我必须将该数据传递给Webapplication2并从Webapplication2的Default.aspx页面的Page_Load中打印该数据。我将如何做到这一点,请帮助任何人。确保我没有使用任何类型的Web服务。实际上我必须通过传递数据从Webapplication1运行Webapplication2。
答案 0 :(得分:1)
几种解决方案:
将数据写入公共数据库,并通过服务代理池或设置sql依赖项以了解何时读取数据;
Webservice,如果不想使用那个开发和ASHX Handler(ashx)并调用它,它就像开发asps页面返回数据一样,但是ASHX更轻;
将文件写入文件系统并从该存储库中读取;
这是否适用于您的问题?如果没有,你想具体做什么?
问候。
答案 1 :(得分:0)
请尝试以下代码:
HttpWebRequest req = null;
HttpWebResponse rsp = null;
string fileName = @"c:\Test.xml";
string uri = "your second application URL with Page, where you want to get the XML Data";
req = (HttpWebRequest)HttpWebRequest.Create(uri);
// req.Proxy = WebProxy.GetDefaultProxy(); // Enable if using proxy
req.Method = "POST"; // Post method
req.ContentType = "text/xml"; // content type
// Wrap the request stream with a text-based writer
StreamWriter writer = new StreamWriter(req.GetRequestStream());
// Write the XML text into the stream
writer.WriteLine(GetTextFromXMLFile(fileName));
writer.Close();
// Send the data to the webserver
rsp = (HttpWebResponse)req.GetResponse();
Stream Answer = rsp.GetResponseStream();
//_Answer = new StreamReader(Answer);
XmlTextReader _Answer = new XmlTextReader(Answer);
阅读XML Data Second Web应用程序页面
Page.Response.ContentType = "text/xml";
// Read XML posted via HTTP
StreamReader reader = new StreamReader(Page.Request.InputStream);
string xmlData = reader.ReadToEnd();
sw.Write(xmlData);
sw.Close();