我正在使用Visual Studio 2010和C#编写一个Web服务,需要通过滚动我自己的SoapExtension来解决我需要的特殊处理。这个SoapExtension当然是实现 ProcessMessage 方法。
这一切都很好,但由于某些原因,对于SoapServerMessage的每个阶段,这个 ProcessMessage 被调用两次(两次,两次),这就是我的问题。任何帮助,弄清楚为什么这是什么以及如何使它只被召唤一次(一次,一次),将非常感激。
顺便说一句:我在网上发现了一些有类似问题的人,比如guy at mofeel.com,这表明他找到了解决方案here at experts-exchange.com,但我不会透露我的信用卡解。这是一个原则。请有人帮帮我吗?
我的 ProcessMessage 方法如下所示:
public override void ProcessMessage(SoapMessage message)
{
if (message is SoapServerMessage)
{
LogFile.WriteLogString(0, "-------------------");
LogFile.WriteLogString(0, "message.Type:" + message.GetType().ToString());
LogFile.WriteLogString(0, "message.Stage:" + message.Stage);
LogFile.WriteLogString(0, "message.Stream.Length:" + message.Stream.Length);
LogFile.WriteLogString(0, "message.Stream.Position:" + message.Stream.Position);
LogFile.WriteLogString(0, "message.Exception:" + message.Exception);
ProcessServerMessage(message);
}
else ProcessClientMessage(message);
}
...当我对我的网络方法进行一次调用时,我得到一个如下所示的日志:
7.7.2010 17:40:25: -------- Log file opened --------
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:330
7.7.2010 17:40:27: [0] message.Stream.Position:330
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterDeserialize
7.7.2010 17:40:27: [0] message.Stream.Length:330
7.7.2010 17:40:27: [0] message.Stream.Position:330
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:BeforeSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:0
7.7.2010 17:40:27: [0] message.Stream.Position:0
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:480
7.7.2010 17:40:27: [0] message.Stream.Position:480
7.7.2010 17:40:27: [0] message.Exception:
7.7.2010 17:40:27: [0] -------------------
7.7.2010 17:40:27: [0] message.Type:System.Web.Services.Protocols.SoapServerMessage
7.7.2010 17:40:27: [0] message.Stage:AfterSerialize
7.7.2010 17:40:27: [0] message.Stream.Length:480
7.7.2010 17:40:27: [0] message.Stream.Position:480
7.7.2010 17:40:27: [0] message.Exception:
注意每个消息阶段是如何被调用两次的?!?!?
答案 0 :(得分:1)
我在这里看到两种可能性。
1-您已在web.config中配置了soap扩展,并且您具有应用于Web方法的自定义SoapExtensionAttribute。
这实际上会将SoapExtension配置两次,因此,由于web.config中的配置,它将运行一次,因为应用于Web方法的属性,它将再次运行。
2-您实际上已在web.config中配置了两次soap扩展名。