我有一个 webservice 项目 c#,当我上传我的项目 @live 时,我收到此错误:
System.IO.IOException:该进程无法访问文件“E:\Sites\www.bivolino.com\bivolino3D\bivo\imgGal\ProductFeedBeslist.xml”,因为它正被另一个进程使用。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs , String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlTextWriter..ctor(String filename, Encoding encoding)
在 e:\Sites\www.bivolino.com\bivolino3D\bivo\OpenGarments\og_webservice\App_Code\ws_og_bivolinogallery.cs:line 1186 中的 ws_og_bivolinogallery.GetItemsBeslist()
在我的本地(本地服务器)中,当我运行我的项目时一切正常,但是@live(实时服务器)我所有的方法都不再起作用了。这是我的代码(例如我的新方法):
[WebMethod(MessageName = "GetItemsBeslist", Description = "Get a list of GAL shirts", CacheDuration = 3600)]
public XmlDocument GetItemsBeslist()
{
XmlTextWriter textWriter = new XmlTextWriter("E:/Sites/www.bivolino.com/bivolino3D/bivo/imgGal/ProductFeedBeslist.xml", Encoding.UTF8);
//E:/Sites/www.bivolino.com/bivolino3D/bivo/imgGal
try
{
if (bRegisterIP)
{
try { LogFiler.ToLog("### IP ### - [" + sRemoteAddress + "]"); }
catch { }
}
XmlDocument xProducts = new XmlDocument();
XmlElement subElm;
XmlElement elmAttr;
XmlNode elmValue;
xProducts.CreateXmlDeclaration("1.0", "utf-8", null);
XmlElement topElm = xProducts.CreateElement("ProductFeed");
topElm.SetAttribute("version", "1.0");
topElm.SetAttribute("timestamp", System.DateTime.Now.ToString().Replace(" ", ":"));
xProducts.AppendChild(topElm);
List<string[]> strarrVelden = new List<string[]>();
strarrVelden.AddRange(DB.GetItemsBeslist());
foreach (string[] rij in strarrVelden)
{
subElm = xProducts.CreateElement("Product");
elmAttr = xProducts.CreateElement("ProductTitle");
elmValue = xProducts.CreateNode(XmlNodeType.Text, "ProductTitle", null); elmValue.Value = "Herenoverhemd Bivolino " + rij[5].ToString();
elmAttr.AppendChild(elmValue);
subElm.AppendChild(elmAttr);
elmAttr = xProducts.CreateElement("Price");
elmValue = xProducts.CreateNode(XmlNodeType.Text, "Price", null); elmValue.Value = rij[6].ToString().Replace(",", ".");
elmAttr.AppendChild(elmValue);
subElm.AppendChild(elmAttr);
elmAttr = xProducts.CreateElement("productURL");
elmValue = xProducts.CreateNode(XmlNodeType.CDATA, "productURL", null); elmValue.Value = rij[1].ToString();
elmAttr.AppendChild(elmValue);
subElm.AppendChild(elmAttr);
elmAttr = xProducts.CreateElement("Category");
elmValue = xProducts.CreateNode(XmlNodeType.Text, "Category", null); elmValue.Value = "Herenoverhemd ";
elmAttr.AppendChild(elmValue);
subElm.AppendChild(elmAttr);
elmAttr = xProducts.CreateElement("ProductDescription");
elmValue = xProducts.CreateNode(XmlNodeType.Text, "ProductDescription", null); elmValue.Value = rij[2].ToString();
elmAttr.AppendChild(elmValue);
subElm.AppendChild(elmAttr);
topElm.AppendChild(subElm);
}
textWriter.WriteStartDocument();
xProducts.Save(textWriter);
textWriter.WriteEndDocument();
textWriter.Close();
return xProducts;
}
catch (Exception ex)
{
return ErrHandle("ERROR - GetItemsBeslist - " + ex.Message, "ERROR - GetItemsBeslist");
}
}
通常这些错误来自未关闭的文件流,但我已经处理好了。我想我忘记了一个重要的步骤,但不知道在哪里。非常感谢您的帮助