Create a new webpage using a WCF service

Posted by sweeney on Stack Overflow See other posts from Stack Overflow or by sweeney
Published on 2010-05-12T21:17:28Z Indexed on 2010/05/12 21:24 UTC
Read the original article Hit count: 238

Filed under:
|
|

Hello,

I'd like to create WCF operation contract which consumes a string, produces a public webpage and then returns the address of this new page.

[ServiceContract(Namespace = "")]
public class DatabaseService
{
    [OperationContract]
    public string BuildPage(string fileName, string html)
    {

        //writes html to file
        //returns public file url

    }
}

This doesn't seem like it should be complicated but i cant figure out how to do it. So far what i've tried is this:

[OperationContract]
public string PrintToFile(string name, string text)
{
    FileInfo f = new FileInfo(name);
    StreamWriter w = f.AppendText();
    w.Write(text);
    w.Close();
    return f.Directory.ToString();
}

Here's the problem. This does not create a file in the web root, it creates it in the directory where the webdav server is running. When i run this on an IIS server it seems to do nothing at all (at least not that i can tell). How can I get a handle to the webroot programmatically so that i can place the resultant file there and then return the public URL? I can tack on the domain name after the fact without issue so if it only returns the relative path to the file that's fine.

Thanks, brian

© Stack Overflow or respective owner

Related posts about wcf

Related posts about html