代码之家  ›  专栏  ›  技术社区  ›  Alfred B. Thordarson

我的SoapExtension收到了两次AfterSerialize消息!

  •  0
  • Alfred B. Thordarson  · 技术社区  · 14 年前

    我正在使用visualstudio2010和C#编写一个需要特殊处理的web服务,我正在通过滚动自己的SoapExtension来解决这个问题。这个SoapExtension当然是实现 方法。

    处理消息

    guy at mofeel.com ,这表明他找到了解决方法 here at experts-exchange.com 但我不会把我的信用卡给你。这是一个原则。有人能帮我吗?

    我的 处理消息 方法如下所示:

    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:
    

    注意每个消息阶段是如何被调用两次的?!?!?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Chris Taylor    14 年前

    我认为有两种可能。

    1-您已经在web.config中配置了soap扩展,并且有一个应用于web方法的自定义SoapExtensionAttribute。

    实际上,这将配置SoapExtension两次,因此它将运行一次,这是因为web.config中的配置,而第二次是因为应用于web方法的属性。

    2-您实际上已经在web.config中配置了两次soap扩展。