Read XSL file from Web Service

Hi Experts,

I have a C# application that does a lot reporting. These reports are web based and formatted using XSL files located on the local drive. A config file with key-value settings is used to store the path of the location of theses 3 files.
For example:
Key="FileOne" Value="H:\formatting\stylesheet\file1.xsl"
Key="FileTwo" Value="H:\formatting\stylesheet\file3.xsl"
Key="FileThree" Value="H:\formatting\stylesheet\file3.xsl"

Everything is working fine as it is. However theses 3 XSL files now need to be shared corporately. And we came up with the use of a web service.

I know basic how to create a web service using Visual Studio 05 - However I need to know if it possible to "dump" these files into a web service  and have their configuration value point to the URL - if it's possible - then how would I implement it?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It is surely possible to do this via a web service. However, I think this would be overkill because (i) it's only a one-way communication from server to client and (ii) the information on the server is static.
Just put the XSL files on your intranet server and use the WebRequest class to fetch it. In the config file you need the URL of the XSL files instead of local file paths and names.
The following is a code snippet from the online help of Visual Studio 05 illustrating the straight forward use of the WebRequest class:

            ' Create a request for the URL.        
            Dim request As WebRequest = WebRequest.Create("")
            ' If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials
            ' Get the response.
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
            ' Display the status.
            ' Get the stream containing content returned by the server.
            Dim dataStream As Stream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            ' Cleanup the streams and the response.
yaney00074Author Commented:
thanx for the feedback

However it's little too complicaed to implement. I need a quick fix.
Let's drop the web service thing if there's a potential problem.

How would I use it with a website?
As I see it, the wesite is approach *is* the quickest and most uncomplicated fix. Web service brings much more implementation overhead.

> However it's little too complicaed to implement.
I don't quite understand you. The above code snippet contains 11 lines of code. This is too complicated? What did you expect?
A web service involves a running script/ at server side handling the request. Although VS05 has great support for web services this is more complicated than inserting 11 lines of code :)
And be aware, using a web service you will get a string or stream as return output. Just the same as with WebRequest.

> How would I use it with a website?
Well, that depends very much on how you used the local file up to now. Do you open a StreamReader, use a string, or just feed the filename to a black box?
Do you use XslCompiledTransform or XmlReader?

What to do:
1) Put the XSL files on your web server, e.g. at
2) Fetch it from the web
      WebRequest req = WebRequest.Create("");
      HttpWebResponse webRes = (HttpWebResponse) req.GetResponse();
3) Initialize a stream reader with the content of file1.xsl
      StreamReader resStream = new StreamReader(webRes.GetResponseStream());
4) Use the stream reader directly,
    or read it to a string for further use
      string resString = resStream.ReadToEnd();
    or use the stream to create a XmlReader
      XmlReader xmlReader = XmlReader.Create(resStream)
    or load the XSL definition into a XslCompiledTransform object
    or write it to a temporary file (if you require a local file for further processing)
      StreamWriter tempStream = new StreamWriter("H:\temp\rand_id.xsl");
5) close resources

If you are using a XslCompiledTransform object, you might get away without any of the above stuff. Just look at the VS05 help for XslCompiledTransform.Load(String). As parameter you can specify an URI to the XSL file. Thus,
   XslCompiledTransform xslt = new XslCompiledTransform();
should also work. I have never tried it, though.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.