我们可以通过Web应用程序调用作为Web服务一部分的aspx页面吗?消耗来自其他页面的网页响应

发布于 2024-10-02 16:30:40 字数 1934 浏览 0 评论 0原文



我编写了一个示例 Web 服务,其中包含某些 .aspx 页面。我编写了一段代码来使用该 Web 服务中的 Webmethods。
现在,是否可以从调用 Web 应用程序(即从 Web 服务外部的另一个 aspx 页面)加载作为 Web 服务一部分的 aspx 页面。

这个场景是怎样的;
1. 我有一个 Web 应用程序正在运行,浏览器中的页面为 Page1.aspx。
2。我创建了一个 Web 服务,它有一个名为 Page2.aspx 的 aspx 页面。
3. Page1.aspx 上有一个按钮。
4. 现在,当客户端单击按钮时,是否可以加载Page2.aspx,它不是Web应用程序的一部分,而是Web服务。

请在这种情况下帮助我。我在谷歌上搜索,但没有得到正确的修复。
我写的示例代码;
网络服务方法;

           [WebMethod]
           public string WelcomeUser(String _userName)
           {
               return "You are Welcome : " + _userName;
           }


消费者网络应用程序; Default.aspx 是启动页。它的加载事件就像;

           WebRequest request  = WebRequest.Create("http://localhost:1741/HelloWorldConsumer/gen.aspx");
           //If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
           //Get the response.
            HttpWebResponse response  = (HttpWebResponse)request.GetResponse();


            // Get the stream containing content returned by the server.
            Stream dataStream  = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
           //Read the content.
            String responseFromServer  = reader.ReadToEnd();

            Test.InnerHtml = responseFromServer;
            //Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();


Gen.aspx 是与 Web 服务通信的。它的页面负载是;

         HelloWorld.Service _objHello = new HelloWorld.Service();
        _objHello.WelcomeUser("Guest");


我想做的是,获取 Gen.aspx 中获得的响应并将其传递到 default.aspx 页面。 谁能帮助我实现这一目标?


提前致谢。

问候,
维杰

I have written a sample web service, which consist of certain .aspx pages. I have written a code to consume webmethods from that web service.

Now, is it possible to load the aspx page which is a part of the web service from the calling web application i.e. from another aspx page which is outside the web service.

How this scenario is;

1. I have one web application running with a page say Page1.aspx in browser.
2. I have created a web service which is having an aspx page say Page2.aspx.
3. There is a button on Page1.aspx.
4. Now, when client click on the button, is it possible to load Page2.aspx, which is not a part of web application, but the web service.

Please help me out in this scenario. I searched on google, but not getting proper fix.

Sample code which I have written;
Web Service Method;

           [WebMethod]
           public string WelcomeUser(String _userName)
           {
               return "You are Welcome : " + _userName;
           }

Consumer web application;
Default.aspx is the startup page. Its load event is like;

           WebRequest request  = WebRequest.Create("http://localhost:1741/HelloWorldConsumer/gen.aspx");
           //If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials;
           //Get the response.
            HttpWebResponse response  = (HttpWebResponse)request.GetResponse();


            // Get the stream containing content returned by the server.
            Stream dataStream  = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
           //Read the content.
            String responseFromServer  = reader.ReadToEnd();

            Test.InnerHtml = responseFromServer;
            //Cleanup the streams and the response.
            reader.Close();
            dataStream.Close();
            response.Close();

Gen.aspx is the one who communicates with web service. Its page load is;

         HelloWorld.Service _objHello = new HelloWorld.Service();
        _objHello.WelcomeUser("Guest");

What I am trying to do is, get response obtained in Gen.aspx and pass it to default.aspx page.
Can anyone help me to achieve this?

Thanks in advance.

Regards,
Vijay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必了 2024-10-09 16:30:41

当您说 aspx 页面是 Web 服务的一部分时,您的意思是什么?假设它是一个普通页面,当通过 HTTP GE/POST 调用时,以某种内容类型(html、xml 等)的 HTTP 响应进行响应,您可以使用 WebRequest (或更具体地说是 HttpWebRequest)调用。请参阅本文以快速入门。

此外,您还有另一个名为 WebClient< 的帮助程序类/a> 这可能会帮助你。

When you say aspx page being part of web service - what do you mean by that? Assuming that its a normal page that when invoked via HTTP GE/POST, responds with HTTP response with some content type (html, xml etc), you can use WebRequest (or more specifically HttpWebRequest) call. See this article for quick start.

Besides you have another helper class called WebClient that may help you in this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文