When you call a Web service
in a Microsoft ASP.NET Web
application, you may receive the following error:
System.IO.FileNotFoundException
You may receive the error if one of the following conditions
is true:
- The worker process does not have permissions to read to the
process Temp directory, and the worker process does not have permissions to write to the process Temp
directory.
Note The XmlSerializer class generates and compiles code on the
fly to perform serialization and deserialization. XmlSerializer uses Code Document Object Model (CodeDom) to perform the
compilation. CodeDom compilation uses temporary files on a disk. If the worker
process does not have the read permissions on the Temp directory and the write
permissions on the Temp directory, then all calls to the Web service fail.
Therefore, the worker process requires the read permissions on the Temp
directory and the write permissions on the Temp directory.
-or- - There are compilation errors in the code that XmlSerializer generated.
Worker Process Account Permissions on the Temp Directory
To
resolve this problem, the ASP.NET worker process account (the ASPNET account or
the NETWORK SERVICE account if your application is deployed on Internet
Information Services [IIS] 6.0) must have read access and write access on the Temp
directory.
Note If you use impersonation, the impersonated user must have
full access on the Temp directory.
To assign required
permissions to the worker process account on the Temp directory, follow these
steps:
- In Microsoft Windows Explorer, locate the %windir%\temp
directory.
- Right-click %windir%\temp, and then click
Properties.
- In the Properties window, click the
Security tab.
- Click Add, type
ServerName\ASPNET, and then
click OK.
Note Replace ServerName with the name of the Web
server.
Replace ASPNET with NETWORK
SERVICE if you deployed your application on IIS 6.0. - Under Allow, click to select the
Full Control check box, and then click
OK.
Find Compiler Errors in the Code That XmlSerializer Generated
To find errors that are generated by the compiler, you must
add a switch to the Web.config file to keep compiler-generated files. To do
this, follow these steps:
- Open the Web.config file in a text editor, such as Notepad.
- Add an XmlSerialization.Compilation switch
to the system.diagnostics section of the code, as follows:
<configuration>
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="4"/>
</switches>
</system.diagnostics>
</configuration> - Run the client application.
The client
application calls the Web service. - Verify that the %windir%\temp directory has the
_tmpname.00.cs file and the _tmpname.out file.
The _tmpname.00.cs
file is the generated source. The _tmpname.out file should have the compiler
errors.
Note Enable the read permissions and enable the write permissions to the
worker process account (ASPNET or NETWORK SERVICE) to write %tmpname% files in
the Temp directory.
This
behavior is by design.
Steps to Reproduce the Behavior
Create a Web service
- Start Microsoft Visual Studio .NET.
- Create a new ASP.NET Web service project by using Microsoft
Visual C# .NET or Microsoft Visual Basic .NET.
By default,
Service1.asmx is created. - Name the project
WebServiceTemp.
- In Solution Explorer, right-click Service1.asmx, and then
click View Code.
- In the Service1.asmx.cs file (or the Service1.asmx.vb file
if you are using Visual Basic .NET), uncomment the default
HelloWorld() WebMethod.
- On the Build menu, click Build
Solution.
Create a Client Web Application
- Create a new ASP.NET Web application by using Visual C#
.NET or Visual Basic .NET.
- Name the project
WebAppTemp.
- In Solution Explorer, right-click
References, and then click Add Web
Reference.
- In the Address text box, type the
following URL for WebServiceTemp:
http://localhost/WebServiceTemp/Service1.asmx - Click Go, and then click Add
Reference.
- Double-click WebForm1 to open the
Page_Load event code.
- Append the following code to the Page_Load
event handler.
Visual C# .NET Sample Code
// Start an instance of the Web service client-side proxy.
localhost.Service1 myProxy = new localhost.Service1();
Response.Write( myProxy.HelloWorld());
Visual Basic .NET Sample Code'Start an instance of the Web service client-side proxy.
Dim myProxy As localhost.Service1 = New localhost.Service1()
Response.Write(myProxy.HelloWorld())
- On the Build menu, click Build
Solution.
Set Permissions on the Temp Directory
To assign required permissions to the worker process account
on the Temp directory, follow these steps:
- In Microsoft Windows Explorer, locate the %windir%
directory.
- Right-click %windir%\temp, and then click
Properties.
- On the Properties window, click the
Security tab.
- Click Add, type
ServerName\ASPNET, and then
click OK.
- Make sure that the Write check box is not
selected under Allow, and then click
OK.
- Run the Web application.
You may receive the
error that is mentioned in the "Symptoms" section of this article.
For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
818364
(http://support.microsoft.com/kb/818364/
)
How to access a Web service in a Windows application by using
Microsoft Visual Basic .NET
314150
(http://support.microsoft.com/kb/314150/
)
Roadmap for XML serialization in the .NET Framework
815169
(http://support.microsoft.com/kb/815169/
)
How to monitor ASP.NET server applications
815153
(http://support.microsoft.com/kb/815153/
)
How to configure NTFS file permissions for security of ASP.NETapplications