Link to home
Start Free TrialLog in
Avatar of GoodJun
GoodJun

asked on

Pass data from webservice to .aspx page and display the .aspx page

I am trying to pass some data (xml) from a webservice (.asmx) to a .aspx page.
in my .asmx page, I used server.transfer and the data can be retrieved from the .aspx page.
But the .aspx page can't be displayed.

The same .aspx page if read the xml data from file directly, it will be displayed. But when call from .asmx page, it can't.

Can somebody give some idea?
Avatar of culshaja
culshaja
Flag of United Kingdom of Great Britain and Northern Ireland image

I am not exatclty sure what you are doing or trying to do but here goes:

I return XML from a webservice to an ASPX page by having afunction as a return type of string and passing the XML back as text by using the OuterXML property of the DOM object if that is what I have got the data stored in. This is retrieved from the webservice by calling the webservice method from the variable which is of the type of the proxy that is created when you add a new web reference to your web application project. This works successfully every time.

I am not sure when and why you are doing a server.transfer so I cannot say if that is an issue. If you could explain it a bit better it might help. It does seem that you might be using server.transfer to try to get the XML data which is what is causing the error.

James :-)
Avatar of GoodJun
GoodJun

ASKER

This is not from .aspx to call .asmx file. It is .asmx file call .aspx file. Here is the full process:
I have a vb6 app call the webservice (.asmx), it pass xml input to the .asmx and the .asmx do calculation and then call a .aspx file with the calculated value and display it on the .aspx page. All the process works except the display portion.
If I save the calculated value to a text file and then open it from the .aspx file, it works. If I pass the calculated value from the .asmx to the .aspx file directly (use server.transfer), the value is transferred but it gives error when try to display it.

I thinkd there may be some issue with redirect a page from .asmx to a .aspx. Do anyone have experience with this?
Avatar of Bob Learned
Are you still having a problem with this?

Bob
I am not sure that a webservice can actually load up a webpage to view. Can you give me an example of the code that you are using?

james :-)
Avatar of GoodJun

ASKER

I still haven't solve it. ( I currently use two steps to make it work. 1.  call the service to create a text file on the server 2. display the .aspx page which read the text file.) I still want to get rid of the step of write the text file  on the server if possible.

Here is the outline of the code:
In my VBA code (client):
    Dim ws As New MSSOAPLib.SoapClient
    Dim returnXml As New DOMDocument
    ws.mssoapinit "http://" & m_ServerName & "myService.asmx?WSDL"
  'step 1
   'objxml is a input xml stream. This step will write the text file on the server.
   'the text file is in xml format and is the calculated value of the buildnetwork function
   ws.BuildNetwork(objXml.XML)
 
'step 2
'display the calculated value, it reads from the text file
     Sheet1.Hyperlinks.Add .Range("L1"), "http://" & m_ServerName & "/myPage.aspx"

These steps works ok.

I want to elimate the step1. with something like this:
   ws.BuildNetwork(objXml.XML,true) 'true signal the webservice to display myPage.aspx and read the xml stream created by function buildnetwork instead of read from text file.

in the myPage.aspx page_load
I can read the xml stream passed by the service. It errors me out when I finished processing the xml and to display the myPage.aspx page. (the End Sub line)


If I read this properly .... doing a server.transfer in a SOAP call to a aspx might break depending how you are packing up your returns etc ...

instead try this ...

Make this calculated value read off the request string ...

Make the webservice return only the calculated value ...

Value = WebService.GetCalculatedValue() then call

if you want to get tricky have the webservice instantiate a webrequest and query the page directly (the return the value from the page from your webservice call)

I think your architecture is faulty.

WebServices don't display anything.  They are equivalent to a class library.  They just return results to the caller.
Therefore Server.Transfer from a webservice to a web site makes no sense.

----

If you just need to have the WebService pass something to a web page, and read the result without the user ever seeing it, then you can use classes in the System.Net namespace to get the page.  See WebClient, HttpWebRequest and HttpWebResponse.
(You might also check System.Net.WebClient.DownloadData() and/or System.Net.WebClient.DownloadFile() ... but I'm not real familar with these.)

Dim wc As New System.Net.WebClient()
Dim html As String = Encoding.ASCII.GetString(wc.DownloadData("http://yourdomain/yourpage.html"))

---

Since the VB6 client program is in control, it has to be responsible for showing anything.  You could have the web service return several different things to the VB6 client (Choose one):
(a) The XML.  The VB6 client would then need to call the ASPX page, passing it the XML.
(b) A complete URL, including the XML encoded as an HTTP query string.  The VB6 client would then just need to start up the URL.
(c) The complete HTML returned from the ASPX page.   The VB6 client would then need to present that in a browser control or browser window.
Avatar of GoodJun

ASKER

farsight,
Your option is close to what I have. I used the (a) option as I stated in the original question, instead of return the huge xml file to client, I stored it in the server to save a round trip.

Are you saying that one can not call a .aspx page to display it from .asmx file? I need some confirmation on this, best with some link that talk about it.
umm you absoutely can as I stated above. You can use the WebRequest object (or the WebClient shortcuts) to call a web page from within a web service.
Avatar of GoodJun

ASKER

gregoryyoung,
Sorry for missed your comments. Can you give a small code snipt to show how the service call the web page and display the page? Thanks,
the soap method would return a string  (HTML)

public string GetHTML() {
            Dim result As WebResponse

            Try
                Dim req As WebRequest
                Dim ReceiveStream As Stream
                Dim encode As Encoding
                Dim sr As StreamReader

                req = WebRequest.Create(url)
                result = req.GetResponse()
                ReceiveStream = result.GetResponseStream()
                encode = System.Text.Encoding.GetEncoding("utf-8")
                sr = new StreamReader( ReceiveStream, encode )
                'value in stream reader just convert it to a string and return ....
            Catch Exc As Exception
                'do whatever you do if you fail
            Finally
                If Not Result Is Nothing Then
                    Result.Close()
                End If
            End Try
}

this woud return a string of HTML to the cient which could then be displayed by the client.

Greg
As Is aid earlier though this sounds backwards architecturally .... that the weservice should process the html then leave it to whoever to display it.
When I say "WebServices don't display anything.", I mean that they have NO code to present user-interface to the end-user.

In your situation, your VB6 client is calling the WebService.   All the VB6 client can do is get data back from the WebService.  If it wants, it can then present that data.

gregoryyoung is right -- and he's saying the same thing I am, but from a different perspective.  When says "you absoutely can", he means the same thing.  He's talking about passing HTML data back to the client (my option c).
Here's the one-liner to finish up his code.
    'value in stream reader just convert it to a string and return ....
    Return sr.ReadToEnd()

What you can NOT do is have the webservice call a webpage and have the webpage response magically be presented on the client.

---
.From http://www.webserviceresource.com/resources/redirect.aspx?resourceid=16 
"Web Services - What Are They?
Web services are a standardized way for one application to invoke a method of another application. These applications may reside on different computers that are some way connected, such as by a local area network or, more commonly, by the Internet. With Web services you have two actors, a client and a server. The server makes some set of methods available. These methods, when called, will perform some action and/or return some data. The client invokes one of the available methods of the server. Like methods in a class library, the methods of a Web service can accept an arbitrary number of input parameters, and can optionally return a result. The Web services standard spells out in great detail how a client can invoke a Web service method from a server. The standard dictates how input parameters and return values are passed from one computer to the other, how faults are handled, and a myriad of other complications."

---

From the way you seem to have architected your solution ...
  (A) VB6 Client <---> (B) .NET WebService <---> (C) .NET aspx page
... I assume that the aspx page is pre-written, and already does the major functionality you need, so you're trying to reuse it.
It might be better to rewrite it so that all the work it does is performed by (D) a new webservice that is available to both the web page and to the VB6 client.

  (A) VB6 Client <--------->   \
                                           \______     (D) new .NET WebService
                                           /
  (C) .NET aspx page <--->   /

(Pardon the ugly pictograph!)

That would result in a pretty standard architecture of having multiple types of clients using the same server.
good explanation of both agreeing opinions farsight.

The only reason I even gave the info was the possibility that he may not have control over the web page.

Have a web service return HTML is architecturally unsound.
Avatar of GoodJun

ASKER

The solution I am looking is:
  (A) VB6 Client ---> (B) .NET WebService ---> (C) .NET aspx page and display at IE

The only portion that I don't know is when the service to call the .aspx page to display it, it gives error.

I know what a normal webservice do and my current code is working this way.
(A) VB6 Client <---> (B) .NET WebService
(A) VB6 Client ---> (C).NET aspx page and display at IE
This is working from day 1 in my code. It is a two step network trip flow. (B and C in the same computer)
I just want to reduce the network trip to one. The answer I expected is Yes/No, if yes, a small examle. if No, give some reason.

Thanks for replying.
We've already told you.    Client <--> webservice <--> aspx is an unusual, awkward, and probably inappropriate architecture.

Still, you can make it work as follows.  For the webservice to aspx connection, use WebRequest and related classes, to get the HTML from the page to the webservice.  For client to webservice, only data flows, so pass back something that the VB6 client can present (data, HTML, or URL).  gregoryyoung's brief example code will do exactly that.  That's all covered above.  The VB6 program will need to fire-up the browser or a browser control or otherwise present the data.

I'm still unclear on exactly what data you intend to move from place to place, and what useful task each major component is providing.  What work is each thing doing?  I don't understand what you're doing with Sheet1.Hyperlinks.Add either.   That'll add a hyperlink, but it won't actually present the data.  If you still don't get it, maybe explaining what data you're passing, or what you're really trying to accomplish would help.
Actually from looking at the example I am thinking more so not that a centralized datastore is needed as opposed to a webservice. As to whether or not it can be done, the above code will do it.


I will offer another architecture that can do the same thing ...
                     /-- VB 6 app
WebService --
                     \-- ASP.NET

both apps write their information to the webservice who holds this information. the webservice can also broker information back to either of them ... Example ...

lets say that the VB 6 app is creating widgets and the Web page is creating / displaying foos. The vb6 ap needs to be able to display foos and the asp.net app needs to be able to display widgets.

pseudo descriptor for webservice

PersistFoo(Foo)
PersistWidget(Widget)
GetWidgetsForFoo(Foo)
GetFoosForWidget(Widget)
GetAllWidgets()
GetAllFoos()
GetFoosForuser(User)
GetWidgetsForUsers(User)

the the webservice becomes the centralized source for both foos and widgets the other two sides are both clients even though they may be doing moreso serverish behaviors

Greg
Avatar of GoodJun

ASKER

I am not talking about the structure is good or not, the app works fine and gives me no error since it goes on online.
Here is the logic behind it.
The vb6 client call the webservice (input lots of data in xml format, the service do a calculation and return data in xml format, I also let the service write the output data in a file on the webserver)
The vb6 client invoke the web page to display, the webpage reads the file written by the webservice in last step and display the data (the webpage has lots of Javascript and used VML to display a graphic presentation of the xml data)

Now, if I want to invoke the webpage from within the webservice (not as what I did from vb6), it gives error. I really just want to know if I can do it (invoke the .aspx page from with the webservice and the client can see the page on their computer). How and why.

Thanks you guys for the time and hope you can still input idea or thoughts. I will give you guys the points anyway.

Thanks,
the webservice does not run on their computer it runs on the server ... there is no way it could possibly do this.
Avatar of GoodJun

ASKER

If a webpage call another webpage (response.redirect or server.transfer). It runs on the server and can do something similar (not exactly).
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> I can do it (invoke the .aspx page from with the webservice and the client can see the page on their computer).

NO, not directly.
>  Why?
The client has ONLY a DATA connection to the webservice.   The webservice has no place to display any presentation.  There is no direct way for the client to get and respond to the presentation HTML.

YES, indirectly.  There are many ways to this.  We explained one of the simplest ways above.
(Other ways include peer-to-peer, server-to-server, etc.)
> how and why
(Again, already answered.)

---

Imagine that you personally are the client program.   The power goes out, so you can't use your own computer to see a particular web page.  So you make a regular standard voice phone call to me (the web service).  I (the web service) can respond to your queries, but it can't DISPLAY anything.   I can bring up a web page if I know (or you tell me) the URL.  You can ask anything you want about the web page, and I can send you DATA describing it.  You can ask questions like "What's the URL?" and I can tell you "HTTP://www.blahblahblah.com".   You can ask, "What's the page look like?", and all I can do is describe it to you; I can not present it to you.  The most precise description you could get is "What is the HTML?", and I would tell you the HTML, character-by-character.  Then, you, the client, would have to save all that HTML as a file, and tell your browser to open it.  Then you could exclaim, "Oh, that's what it looks like!"

That's intended to describe the kind of "pipe" the VB6 client program has to the web service.  It's just data.  Make a method call; get the result(s) of that method call.  That's all it can do.

---

If both the web service and web page (aspx) have access to the same data store (like when they're on the same machine), you could indeed save the huge XML in that data store.  You would want the web service to tell the VB6 client a small unique identity for that XML file.  Then the VB6 client could open the web page (aspx), passing it the unique identity info.  The web page would grab the proper file, process it, and send the resulting HTML page back to the client for presentation.  (That binds the webservice and the web page tightly together, which is also not good architecture.)

I propose that you think about this question "How can I get the required data to the VB6 client to display the page?",
not this question "How can I make some other thing display the page on my client computer?"  I think using that perspective will get you an answer quickly and easily.
Avatar of GoodJun

ASKER

Ok. Good enough. I know that I can not save one step. I have to maintain my original two step approach, vb6 to webservice to get the data, then vb6 to the page to display it. Farsight, please leave a comments on my other thread and I will give you points on that one.
https://www.experts-exchange.com/questions/20972114/From-webservice-call-aspx-page-and-display-the-aspx-page-1000pt.html

Thanks guys for clarify it.