Can we call aspx page which is a part of web service through a web application + consume webpage response from other page

StackOverflow https://stackoverflow.com/questions/4201271

Question



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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top