各位同仁:
  我在使用MS介绍其智能客户端时所涉及的两个通用的库 AppStart和AppUpdate进行客户端程序更新,当更新网站在windows2003,XP系统的IIS上均能成功使用,但是在windows server 2008 r2操作系统的IIS7.0 上却不能使用,报错:“System.Net.WebException: 远程服务器返回错误: (405) 不允许的方法”,经过调试,发现报错信息如下:
在 System.Net.WebException 中第一次偶然出现的“System.dll”类型的异常
Error accessing Url http://10.164.1.65/FZLD_Server/UpdateVersion.xml
在 System.Net.WebException 中第一次偶然出现的“AppUpdater.dll”类型的异常
System.Net.WebException: 远程服务器返回错误: (405) 不允许的方法。
   在 System.Net.HttpWebRequest.GetResponse()
   在 Microsoft.Samples.AppUpdater.WebFileLoader.UpdateFile(String url, String filePath) 位置 D:\Work\Project\FZLaborDispatch\AppUpdater\WebFileLoader.cs:行号 109
   在 Microsoft.Samples.AppUpdater.ServerManifest.Load(String url) 位置 D:\Work\Project\FZLaborDispatch\AppUpdater\ServerManifest.cs:行号 50
   在 Microsoft.Samples.AppUpdater.AppUpdater.CheckForUpdates() 位置 D:\Work\Project\FZLaborDispatch\AppUpdater\AppUpdater.cs:行号 277
   在 Microsoft.Samples.AppUpdater.ServerPoller.RunThread() 位置 D:\Work\Project\FZLaborDispatch\AppUpdater\ServerPoller.cs:行号 125跟踪到代码中,发现在UpdateFile()函数中报错,现将代码公布如下:
public static void UpdateFile(string url, string filePath)
{
HttpWebResponse Response;

//Retrieve the File
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
Request.Headers.Add("Translate: f");
Request.Credentials = CredentialCache.DefaultCredentials; //Set up the last modfied time header
if (File.Exists(filePath)) 
Request.IfModifiedSince = LastModFromDisk(filePath); try 
{
Response = (HttpWebResponse)Request.GetResponse();
}
catch(WebException e) 
{
if (e.Response == null) 
{
Debug.WriteLine("Error accessing Url " + url);
throw;
} HttpWebResponse errorResponse = (HttpWebResponse)e.Response;

//if the file has not been modified
if (errorResponse.StatusCode == HttpStatusCode.NotModified)
{
e.Response.Close();
return;
}
else 
{
e.Response.Close();
Debug.WriteLine("Error accessing Url " + url);
throw;
}
}

Stream respStream = null; try 
{
respStream = Response.GetResponseStream();
CopyStreamToDisk(respStream,filePath); DateTime d = System.Convert.ToDateTime(Response.GetResponseHeader("Last-Modified"));
File.SetLastWriteTime(filePath,d);

catch (Exception)
{
Debug.WriteLine("APPMANAGER:  Error writing to:  " + filePath);
throw;
}
finally 
{
if (respStream != null)
respStream.Close();
if (Response != null)
Response.Close();
}
}
故障应该发生在Response = (HttpWebResponse)Request.GetResponse();行
请教大家有没有碰到类似的问题。使用的IIS7.0,开始怀疑是权限未配置,但是排查后发现不是权限问题。会是什么原因呢?请大家不吝赐教。

解决方案 »

  1.   

    估计是没有对 .xml 进行meta映射的原因http://blog.csdn.net/WhatWhoWhere/article/details/6033616
      

  2.   


    好像是这个原因,但是我的url是http://10.164.1.65/FZLD_Server/UpdateVersion.xml,请问*.xml的程序映射的可执行文件是什么?谢谢
      

  3.   

    好像不是多线程冲突,应该是*.xml未设置处理程序映射。
      

  4.   

    选择站点-》IIS-》处理程序映射-》添加脚本映射(对应扩展名)
    http://www.cnblogs.com/tearer/archive/2012/10/24/2737823.htmlIIS7.5 伪静态 脚本映射 配置方法 
    http://technet.microsoft.com/zh-cn/library/cc771240
      

  5.   


    你好,我在设置 处理程序映射-》添加脚本映射 设置*.xml的脚本映射,但是不知道可执行程序选择什么,从网上搜索没看到,第一次接触这个,感觉7.0比5.1复杂多了
      

  6.   

    有人知道*.xml在处理程序映射中,可执行程序 怎么配置吗?
    谢谢大家。
      

  7.   

    文件扩展名:.xml
    MIME类型:text/xml
      

  8.   

    你的url
    http://10.164.1.65/FZLD_Server/UpdateVersion.xml
    在浏览器中如果能访问,HttpWebRequest也应该能够直接访问的,采用GET方法应该是可以的,服务器默认设置就可以,无需特殊设置
      

  9.   

    嗯,没错,我把IIS7.0删掉重新安装,使用默认安装,现在HttpWebRequest.GetResponse()可以获取了,但是现在又有一个新问题,我要获取http://10.164.1.65/FZLD_Server/UpdateVersion.xml的文件,在网页浏览中有内容,但是我使用HttpWebResponse.GetResponseStream()获取后,获取到的Stream长度却为0,这事为什么????
    急死我了,谢谢大家
      

  10.   

    那个Stream不支持查看长度,你怎么知道是0?
      

  11.   

    这个错误是不经常发生,时间不定,请问,我是自己写的一个程序winForm程序,应该怎样处理
      

  12.   

    对了,我用的是多线程,测试时出错后 vs2012把错误定位在多线程的异步回调函数上 public void MyAsyncCallback(IAsyncResult ar)
            {
                string s;
                int iExecThread;            // Because you passed your original delegate in the asyncState parameter
                // of the Begin call, you can get it back here to complete the call.
                MethodDelegate dlgt = (MethodDelegate)ar.AsyncState;            // Complete the call.
                s = dlgt.EndInvoke(out iExecThread, ar);
                //MessageBox.Show(String.Format("The delegate call returned the string: {0}, and the number {1}", s, iExecThread.ToString()));            //Console.WriteLine(string.Format ("The delegate call returned the string:   "{0}", and the number {1}", s,iExecThread.ToString() ) );
            }