You Receive a "System.IO.FileNotFoundException" Error When the Client Application Calls a Web Servic...

本文介绍了解决在ASP.NET Web应用程序中调用Web服务时遇到的FileNotFoundException错误的方法。错误出现的原因可能是工作进程没有读写临时文件夹的权限,或是由XmlSerializer生成的代码存在编译错误。文章提供了设置工作进程账户权限和查找生成代码中的错误的具体步骤。

SYMPTOMS

When you call a Web service in a Microsoft ASP.NET Web application, you may receive the following error:
System.IO.FileNotFoundException

Back to the top

CAUSE

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.

Back to the top

RESOLUTION

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:
1. In Microsoft Windows Explorer, locate the %windir%\temp directory.
2. Right-click %windir%\temp, and then click Properties.
3. In the Properties window, click the Security tab.
4.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.
5.Under Allow, click to select the Full Control check box, and then click OK.

Back to the top

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:
1.Open the Web.config file in a text editor, such as Notepad.
2.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>
3. Run the client application.

The client application calls the Web service.
4.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.

Back to the top

STATUS

This behavior is by design.

Back to the top

MORE INFORMATION

Steps to Reproduce the Behavior

Create a Web service
1.Start Microsoft Visual Studio .NET.
2.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.
3.Name the project WebServiceTemp.
4. In Solution Explorer, right-click Service1.asmx, and then click View Code.
5.In the Service1.asmx.cs file (or the Service1.asmx.vb file if you are using Visual Basic .NET), uncomment the default HelloWorld() WebMethod.
6.On the Build menu, click Build Solution.

Create a Client Web Application
1.Create a new ASP.NET Web application by using Visual C# .NET or Visual Basic .NET.
2.Name the project WebAppTemp.
3. In Solution Explorer, right-click References, and then click Add Web Reference.
4. In the Address text box, type the following URL for WebServiceTemp:

http://localhost/WebServiceTemp/Service1.asmx
5.Click Go, and then click Add Reference.
6.Double-click WebForm1 to open the Page_Load event code.
7.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())
8. On the Build menu, click Build Solution.

Back to the top

Set Permissions on the Temp Directory


To assign required permissions to the worker process account on the Temp directory, follow these steps:
1.In Microsoft Windows Explorer, locate the %windir% directory.
2. Right-click %windir%\temp, and then click Properties.
3.On the Properties window, click the Security tab.
4.Click Add, type ServerName\ASPNET, and then click OK.
5.Make sure that the Write check box is not selected under Allow, and then click OK.
6.Run the Web application.

You may receive the error that is mentioned in the "Symptoms" section of this article.

FROM: http://support.microsoft.com/?id=823196

转载于:https://www.cnblogs.com/ice5/articles/1205516.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值