Solved

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

Posted on 2004-03-25
23
926 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:GoodJun
  • 8
  • 8
  • 4
  • +2
23 Comments
 
LVL 7

Expert Comment

by:culshaja
ID: 10685403
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 :-)
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10687251
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?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10924168
Are you still having a problem with this?

Bob
0
 
LVL 7

Expert Comment

by:culshaja
ID: 10926252
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 :-)
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10940353
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)


0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10954300
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)

0
 
LVL 12

Expert Comment

by:farsight
ID: 10977911
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.
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10980236
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.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10980607
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.
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10981293
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,
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10981352
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
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10981360
As Is aid earlier though this sounds backwards architecturally .... that the weservice should process the html then leave it to whoever to display it.
0
 
LVL 12

Expert Comment

by:farsight
ID: 10982843
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.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10983155
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.
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10987422
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.
0
 
LVL 12

Expert Comment

by:farsight
ID: 10987836
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.
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10988427
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
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10989489
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,
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 10989654
the webservice does not run on their computer it runs on the server ... there is no way it could possibly do this.
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10989986
If a webpage call another webpage (response.redirect or server.transfer). It runs on the server and can do something similar (not exactly).
0
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
ID: 10990000
what you are asking would be the equivalent of writing a web page that you can go to to start up a browser on my computer ... The client would be the one responsible for executing this ... the webservice could tell the client to do it but it would be the clients responsibility.
0
 
LVL 12

Expert Comment

by:farsight
ID: 10991582
> 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.
0
 
LVL 10

Author Comment

by:GoodJun
ID: 10995925
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.
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/Q_20972114.html

Thanks guys for clarify it.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now