.net 用soap扩展类把 soap消息记录到日志文件
.net 用soap扩展类 把 soap消息记录到日志文件中,请求soap消息可以记录到日志文件,但是在响应 消息出现错误:System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.NotSupportedException: 不支持所指定的方法。
在 System.Web.HttpResponseStream.Read(Byte[] buffer, Int32 offset, Int32 count)
在 System.Web.Services.Protocols.SoapExtensionStream.Read(Byte[] buffer, Int32 offset, Int32 count)
在 System.Xml.XmlTextReaderImpl.InitStreamInput(Uri baseUri, String baseUriStr, Stream stream, Byte[] bytes, Int32 byteCount, Encoding encoding)
在 System.Xml.XmlTextReaderImpl..ctor(String url, Stream input, XmlNameTable nt)
在 System.Xml.XmlDocument.Load(Stream inStream)
在 eHealthSer.TraceExtension.WriteOutput(SoapMessage message) 位置 C:\workspace\eHealthSer\eHealthSer\security\TraceExtension.cs:行号 132
在 eHealthSer.TraceExtension.ProcessMessage(SoapMessage message) 位置 C:\workspace\eHealthSer\eHealthSer\security\TraceExtension.cs:行号 65
在 System.Web.Services.Protocols.SoapMessage.RunExtensions(SoapExtension[] extensions, Boolean throwOnException)
在 System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
在 System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
在 System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- 内部异常堆栈跟踪的结尾 ---
soap 扩展类如下:
public class TraceExtension :SoapExtension
{
log4net.ILog logger;
Stream httpStream;
public override object GetInitializer(Type serviceType)
{
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer)
{
logger = log4net.LogManager.GetLogger("Debug");
logger.Debug("Initialize:" + initializer);
}
public override System.IO.Stream ChainStream(System.IO.Stream stream)
{
httpStream = stream;
return httpStream;
}
public override void ProcessMessage(SoapMessage message)
{
switch (message.Stage)
{
//object --xml 对象解析成XML格式之后的阶段
case SoapMessageStage.AfterSerialize:
WriteOutput(message);
break;
//object --xml 对象解析成XML格式之前的阶段
case SoapMessageStage.BeforeSerialize:
test(message);
break;
//xml -- object XML 格式解析成对象之前的阶段
case SoapMessageStage.BeforeDeserialize:
WriteInput(message);
break;
case SoapMessageStage.AfterDeserialize:
break;
default:
break;
}
}
private void WriteInput(SoapMessage message)
{
if (message is SoapServerMessage)
{
XmlDocument doc = new XmlDocument();
long posStream = httpStream.Position;
//httpStream = message.Stream;
doc.Load(httpStream);
httpStream.Position = posStream;
logger.Debug("------------Input SoapMessage--------------");
// logger.Debug("Headers:"+doc.);
logger.Debug("PlayLoad:" + doc.InnerXml);
// httpStream.Flush();
}
}
private void WriteOutput(SoapMessage message)
{
if (message is SoapServerMessage)
{
XmlDocument doc = new XmlDocument();
doc.Load(httpStream);
logger.Debug("------------Output SoapMessage------------");
logger.Debug("PlayLoad:");
}
}
--------------------编程问答-------------------- 有没有谁知道 ,帮帮忙 ,困恼了很久了
补充:.NET技术 , ASP.NET