0

I have a problem with my webservice (no WCF).

So, I have a webservice stored on my server (windows 2008 R2). I have a function to create an XML file with XmlTextWritter. When I launch the webservice into my server's browser, and I test my function, all run normally. But when I called this function with my client app (WPF on my computer, not on server), I have this error :

Server can't process this request. ---> Unable to find 'C:\inetpub\wwwroot\WebServicePROJETDEV\App_Data\Worlds\test.xml'.

The XmlTextWritter must created the file but it sayed it not found it. This error occured just when I'm using the client side.

This is my function GenerateXML where the variable "path" is the name of world (String parameter of function) :

try {
    XmlTextWriter rw = new XmlTextWriter("C:\\inetpub\\wwwroot\\WebServicePROJETDEV\\App_Data\\Worlds\\" + path + ".xml", Encoding.UTF8);

    rw.Formatting = Formatting.Indented;

    rw.WriteStartDocument();

        rw.WriteStartElement("world");
            rw.WriteStartElement("name");
            rw.WriteString(nameOfWorld);
            rw.WriteEndElement();
        rw.WriteEndDocument();

    rw.Flush();
    rw.Close();

    return true;
}
catch(Exception e)
{
    Console.WriteLine(e.StackTrace);
    return false;
}

Someone know why server side, all run, and client side, the script can't create/found the file ?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Have you checked that the folder you're trying to access exists? – Michael Sondergaard Jun 18 '12 at 20:02
  • Yes, it exist because when I'm server side, all run and the file is created normally. I've checked access rights too, all is correct :/ – user1448932 Jun 18 '12 at 20:04
  • Right, does the folder exist on your local machine aswell? The full path needs to exist and, as you say, permissions should be correct. Consider using a relative path instead, such that it'll work from the app's base directory rather than a hardcoded path. – Michael Sondergaard Jun 18 '12 at 20:06
  • Why folder need to exist on local machine ? The script is on the server ? I have try with the same file on local machine, but same error... – user1448932 Jun 18 '12 at 20:07
  • If you intended for the code to run on the server then it shouldn't. How are you calling the function in the WPF-app? I assumed it was meant to be client-side because of the call to Console.WriteLine. – Michael Sondergaard Jun 18 '12 at 20:10
  • I call this function when I consumed the webservice (Service reference in the wpf application). Your right, the "Console.WriteLine" is an error, I deleted it. Idea is client send a name of world to the webservice, and the webservice create an xml file named with the name of world, and store this name into the file. So I can't run the script client side right ? – user1448932 Jun 18 '12 at 20:15
  • You shouldn't use `new XmlTextWriter()`. It's been deprecated since .NET 2.0. Use `XmlWriter.Create()` instead. – John Saunders Jun 18 '12 at 20:35
  • The same error occured with XmlWriter.Create()... – user1448932 Jun 18 '12 at 20:44
  • I expected the same error, but at least you're not writing .NET 1.1 code. – John Saunders Jun 19 '12 at 03:20
  • You may need to show us what you mean by calling "client side" and "server side" because you don't make much sense. – John Saunders Jun 19 '12 at 03:21

0 Answers0