0

我需要设置一个系统来接收完整的肥皂消息(然后由第三方应用程序处理该消息)并且无法理解如何使用 WCF 执行此操作。

传入消息的格式如下:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing">
  <s:Header>
      <wsa:MessageID>3AAAF216520F</wsa:MessageID>
      <wsa:Action>SendDocument</wsa:Action>
      <wsa:To>~serviceURI~</wsa:To>
      <wsa:From><wsa:Address>~fromServiceURI~</wsa:Address></wsa:From>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="D6CD5232-14CF-11DF-9423-1F9A910D4703">
          <wsu:Created>~Created~</wsu:Created>
          <wsu:Expires>~Expires~</wsu:Expires>
          </wsu:Timestamp>
          <wsse:UsernameToken>
              <wsse:Username>ePAQ</wsse:Username>
          </wsse:UsernameToken>
      </wsse:Security>
  </s:Header>
 <s:Body>
    <i:DistributionEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">...    </i:DistributionEnvelope>  
  </s:Body>
</s:Envelope>
4

2 回答 2

1

您可以使用 WCF 通用合同:

[OperationContract(Action="*", ReplyAction="*")]
    System.ServiceModel.Channels.Message ProcessMessage(System.ServiceModel.Channels.Message msg);
}
于 2013-09-12T15:06:31.643 回答
1

看看这种方法,看看它是否有帮助。在你的 WCF 服务项目中实现一个消息检查器,我给你一个我实现登录/注销soap消息的例子。

public class LogSoapMessageInterceptor : IDispatchMessageInspector
{
    public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
    {
        MessageBuffer buffer = request.CreateBufferedCopy(Int32.MaxValue);
        request = buffer.CreateMessage(); //this step is important http://goo.gl/u4eBT
        Message message = buffer.CreateMessage(); //this step is important http://goo.gl/u4eBT

        StringBuilder sb = new StringBuilder();
        using (XmlWriter xw = XmlWriter.Create(sb))
        {
            message.WriteMessage(xw);
            xw.Close();
        }
        Logger.Log(String.Format("Received SOAP Request:\n{0}", sb.ToString()));

        return null;
    }

    public void BeforeSendReply(ref Message reply, object correlationState)
    {
        MessageBuffer buffer = reply.CreateBufferedCopy(Int32.MaxValue);
        reply = buffer.CreateMessage();
        Logger.Log(String.Format("Sending SOAP Reply:\n{0}", buffer.CreateMessage().ToString()));
    }
}

public abstract class AbstractInterceptionBehavior<T> : IEndpointBehavior where T : IDispatchMessageInspector, new()
{
    public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
    {
    }

    public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
    {

    }

    public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
    {
        T inspector = new T();
        endpointDispatcher.DispatchRuntime.MessageInspectors.Add(inspector);
    }

    public void Validate(ServiceEndpoint endpoint)
    {
    }
}

public class LogSoapMessageBehavior : AbstractInterceptionBehavior<LogSoapMessageInterceptor>
{
}

public class LogSoapMessageBehaviorExtensionElement : AbstractInterceptionBehaviorExtentionElement<LogSoapMessageBehavior>
{
}

//related configuration settings
<extensions>
  <behaviorExtensions>
    <add name="logSoapMessageBehavior"
         type="xyz.com.Web.Interceptors.LogSoapMessageBehaviorExtensionElement, xyz.com" />
  </behaviorExtensions>
</extensions>
于 2013-09-12T14:41:44.537 回答