0

看来我们的应用程序存在程序集泄漏。我注意到,在使用 HttpWebRequest 对象调用 Web 服务调用的任何调用中,都会在调用 httpWebRequest.GetResponse() 时加载动态程序集

我可以看到程序集通过调试器加载('w3wp.exe'(托管):加载'7-6jav6v',未加载符号。)但我无法弄清楚为什么会发生这种情况。

以前有没有其他人经历过这种情况?

编辑:为这个问题添加说明。在 C# 中,当您创建 XmlSerializer 时,会创建一个程序集来完成序列化。除非您使用工具提前为您执行此操作,否则这种情况总是会发生。如果使用 (Type type) 或 (Type type, string "namespace") 的构造函数,则只会生成 1 个程序集。如果您使用任何其他构造函数,则将为每个序列化生成一个新程序集。

上述问题并非如此。

我们的代码库中有一段代码手动进行了一次soap调用并返回一个字符串(字符串是xml,例如:)。每次执行此代码块时,都会创建一个新程序集。在检查其中一个程序集时,它被引用为“XmlSerializationWriter1.Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader1.XmlSerializer1.ArrayOfObjectSerializer.ArrayOfObjectSerializer1.ArrayOfObjectSerializer2”

为了更好地理解 - 代码块如下所示,当最后一行执行时生成程序集...多个程序集,每次运行此块时一个程序集。

HttpWebRequest oHttpWebRequest =(HttpWebRequest)WebRequest.Create("URL TO WEBSERVICE"); 
oHttpWebRequest.Timeout =((1000*60)*30);
oHttpWebRequest.Method ="POST" ; 
oHttpWebRequest.ContentType ="text/xml" ; 
oHttpWebRequest.Headers.Add("SOAPAction: http://www.tempuri.com/"+WebMethodName); 
StreamWriter oStreamWriter = new StreamWriter(oHttpWebRequest.GetRequestStream()) ; 

string SoapRequest=@"<soap:Envelope xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""><soap:Body>";
SoapRequest=SoapRequest + HttpUtility.HtmlDecode(XmlHttpRequestData);
SoapRequest=SoapRequest + @"</soap:Body></soap:Envelope>";
oStreamWriter.Write(SoapRequest); 
oStreamWriter.Close();

oHttpWebRequest.ProtocolVersion.Build;

WebResponse oWebResponse = oHttpWebRequest.GetResponse() ; 
4

2 回答 2

1

根据您在 Sky Sanders 回答下方的评论,生成的程序集用于 XML 序列化。序列化程序集是动态生成的,除非您使用XML 序列化程序生成器工具 (Sgen.exe)预先生成它们。如果这样做,将使用现有程序集并且不会生成任何程序集

于 2010-03-02T01:47:12.197 回答
0

Is the schema of the xml for the web services you call fixed, or dynamic? If you are calling arbitrary web services that each take arbitrary XML messages as input and return arbitrary XML messages as output...then the XmlSerializer is going to create a new assembly for each schema. If each message essentially uses the same schema, but varies enough in structure, even though they could use a common schema, the XmlSerializer is only so capable...its going to generate a assembly to handle each specific schema it identifies.

Like Thomas said, if your schema is fixed, use the XML Serializer Generator Tool to pre-generate your serialization assemblies.

于 2010-03-02T03:20:10.540 回答