How to call .aspx page from a web web service(service.svc?

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

  • 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

  • Answer:

    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 http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx (or more specifically HttpWebRequest) call. See http://www.west-wind.com/presentations/dotnetwebrequest/dotnetwebrequest.htm for quick start. Besides you have another helper class called http://msdn.microsoft.com/en-us/library/system.net.webclient%28VS.80%29.aspx that may help you in this.

Vijay Balkawade at Stack Overflow Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.