Multiple Classes and Namespace

E

Elroyskimms

RE-POST:
http://www.developersdex.com/vb/message.asp?r=3661767&p=1121

I have a Web Service, it works very well. Multiple servers connect to
the Web Service, it performs its "special magic" as expected and I am
very happy with the result. Enter the customer who wants to make a
change to the system...

When the Web Service is finished, I need it to pass along an XML file
using HTTP GET/POST and then capture an XML response from the GET/POST
operation. I can make the Web Service GET/POST without a problem, but
the XMLTextReader I use to capture the response is part of the
System.Web.UI.Page class, and I cannot inherit that class within my Web
Service. Is there an XMLTextReader equivalent for a Web Service? Sample
code? Thanks for your help!

-Elroyskimms
 
E

Elroyskimms

Cor,

Thanks for the suggestion. The XML response that I am trying to capture
is not an actual file, it is a dynamically generated response based on
the XML document that I sent to the other machine. I am forced to use
GET/POST based on the other system's requirements. The response comes
from something similar to a response.write("Hello world") command. How
can I access that from a Web Service? Unfortunately, a blind transfer
is not acceptable. I have to receive their acknowledgement. If I am not
inheriting the Web Service class, but rather inheriting the Web Page
class, I can access this using the following code:

Dim Reader As XmlTextReader = Nothing
' Load the reader with the data file and ignore all white space
nodes.
Reader = New XmlTextReader(Request.InputStream)
Reader.WhitespaceHandling = WhitespaceHandling.None
' Parse the file and display each of the nodes.
While Reader.Read()
....
End While
Request.Inputstream is not available in the Web Service class...
 
E

Elroyskimms

Cor,

I am trying to use the Request.InputStream already, and it works in
System.Web.UI.Page however, this particular project is a web service,
which inherits System.Web.Services.WebService. I could just blindly
POST the XML to the outside server, but I really need to view some sort
of acknolwedgement.

Thanks!

-Elroyskimms
 
C

Cor Ligthert

Elroy

My problem is that I cannot understand you,

When you use a webservice with VSNet it is only a passing in the method
using the XML file.

Something by instance as
dim myxml file as WhatEverXML =
mywebservice.GetMyOwnXMLFileFromTheWebService

Therefore I cannot see the problem

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Elroyskimms,
It sounds like you have a web service & you want to know how to send a File
or attachment to the web service? Correct?

Using System.Web.UI.Page is NOT the answer. As that is for creating a Human
Readable pages, you are dealing with a Web Service they are different &
handle a number of things in specific ways, hence they don't inherit from
UI.Page...

In addition to Cor's suggestion.

The "easiest" way (that I know of) is to have an XmlNode or String parameter
to the Web Service's method. Where the XmlNode or String is the data itself
(not the name of the file, but the actual data). If you are sending binary
data, such as an Image file, I would use a Byte Array for the parameter.

The more complete method (that I know of) is to use the "Sending
attachments" facility of Web Services Enhancements (WSE)
http://msdn.microsoft.com/webservices/building/wse/default.aspx


Hope this helps
Jay
 
E

Elroyskimms

I apologize for not being more clear. I will try again to explain the
problem. First, I am not trying to send a file of any type to the
webservice.

Part of the webservice is to POST some XML to an outside server. Here
is the sample code:

Dim sw As StringWriter = New StringWriter
Dim writer As XmlTextWriter = New XmlTextWriter(sw)
writer.WriteStartDocument()
writer.WriteStartElement("submit")
writer.WriteElementString("sample_a", myData)
writer.WriteElementString("sample_b", myOtherData)
writer.WriteEndElement()
writer.Flush()
writer.Close()
Dim sb As StringBuilder = New StringBuilder
Dim request As HttpWebRequest =
CType(WebRequest.Create(pingUrl, HttpWebRequest)

(pingURL is the outside server receiving the POST)
Once this completes, I need to receive a response from the outside
server, an acknowledgement that they received the XML I sent. Here is
the problem. The code I use in other projects to access the response is
below:

Dim Reader As XmlTextReader = Nothing
' Load the reader with the data file and ignore all white space
nodes.
Reader = New XmlTextReader(Request.InputStream)
Reader.WhitespaceHandling = WhitespaceHandling.None
' Parse the file and display each of the nodes.
While Reader.Read()
....
End While

This code works fine in other projects because those projects are not
Web Services, they inherit System.Web.UI.Page. However, this new
project IS a Web Service, which inherits
System.Web.Services.WebService. Request.InputStream does not appear to
be a part of the Web Service class, so I cannot use my current method
to access the response from the outside server. I need to find a way to
access the InputStream from within a Web Service. If you have any
suggestions, sample code would be greatly appreciated. I hope this
clears up any confusion. Thanks!

-A
 
J

Jay B. Harlow [MVP - Outlook]

Elroyskimms,
You still aren't being very clear, possible because you have taken us in a
couple of different directions & we have preconceived notions of what you
really want, plus you've dismissed Cor's suggestion, which I believe is what
you really want...


If I follow this post correctly (and only this post):

You are posting data to a Web Server using the POST method, and you want to
get the Response back from this POST. Correct?

You are posting this data inside a method of a Web Service, which IMHO
doesn't apply, as you are simply posting data to a Web Server expecting a
Response.


Your sample has you started in the right direction:

You need to use HttpWebRequest.GetResponse to get the results of posting the
data to the Web Server.

Dim request As HttpWebRequest =
DirectCast(WebRequest.Create(pingUrl), HttpWebRequest)

Dim response As HttpWebResponse = DirectCast(request.GetResponse(),
HttpWebResponse)

Dim reader As XmlTextReader = Nothing
reader = New XmlTextReader(response.GetResponseStream())

This code works fine in other projects because those projects are not
Web Services, they inherit System.Web.UI.Page. However, this new
project IS a Web Service, which inherits
System.Web.Services.WebService. Request.InputStream does not appear to
Does it actually work? Request.InputStream on a WebPage would be the request
to that page, not the request/post to the other server!

Hope this helps
Jay
 
E

Elroyskimms

Jay,

You understand corretly the problem I am having... but my error
messages are no longer working. My web.config file is fine, I've always
seen the ASP.Net error messages (I'm running this on my local machine,
local admin account, etc.) I have made no changes to any configurations
whatsoever. As a test, I performed a divide-by-zero operation and
instead of the ASP.Net error message, it went to HTTP 500 Internal
Server Error. Local service accounts have also not been changed. My
best guess is that it has something to do with a MS Critical Update.
Can anyone help me on this?

Back to the topic at hand...

The request.inputstream works rather well (for Human Readable pages).
It seemed a much simpler and more elegant solution than some others I
had tried. I currently have several systems using it more than a
thousand times a day without a problem. However, as you know, using
request.inputstream is for human readable pages, not web services.

I am getting an error somewhere in the sample you sent, but my current
error message problem prevents me from viewing it. Once I get that
resolved, I will be able to comment on your suggestion. Thanks for your
help!

-A
 
J

Jay B. Harlow [MVP - Outlook]

Elroyskimms,
Normally what I do is get the "code" working in a Console or Windows Forms
application first, then cut & paste the code into the Web Service.

Otherwise you can be fighting too many battles...

Hope this helps
Jay
 
E

Elroyskimms

Any ideas on why my ASP.Net errors have vanished, leaving me with only
HTTP 500 Internal Server Error?

-Elroyskimms
 
E

Elroyskimms

Don't I feel stupid... somehow "friendly" (aka meaningless) error
messages was switched on in IE. That won't happen again.

Unfortunately, the HTTP 500 Internal Server Error I get when using the
sample code still happens a the following line:

Dim response As HttpWebResponse = DirectCast(request.GetResponse(),
HttpWebResponse)

Any ideas?

-A
 
E

Elroyskimms

Don't I feel stupid... somehow "friendly" (aka meaningless) error
messages was switched on in IE. That won't happen again.

Unfortunately, the HTTP 500 Internal Server Error I get when using the
sample code still happens a the following line:

Dim response As HttpWebResponse = DirectCast(request.GetResponse(),
HttpWebResponse)

Any ideas?

-A
 
J

Jay B. Harlow [MVP - Outlook]

Elroyskimms,
Does the code run outside of a web service? Such as a Console or Windows
Forms application.

Hope this helps
Jay
 
E

Elroyskimms

Thank you all very much for your prompt and incredibly helpful replies.
If anyone else has a similar issue, your posts will certainly be of
great help. As it turns out, the HTTP 500 error was THEIR INTERNAL
server error... they changed the communication spec's for their system
and didn't tell me. I received an updated spec sheet, tried your sample
code and it worked like a charm. Thank you for your help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top