English 中文(简体)
之后 我看到服务参数无效
原标题:After Enable IDispatchMessageFormatter I see nullable parameters in service
  • 时间:2011-10-12 11:19:58
  •  标签:
  • wcf

在为行动行为添加我的格式之后:

    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
        ServerMessageFormatter Formatter = new ServerMessageFormatter();
       dispatchOperation.Formatter = Formatter;
    }

在形式上,我有空洞的降水方法,因此我想使用默认行为。

 public void DeserializeRequest(System.ServiceModel.Channels.Message message, object[] parameters)
    {}

但是,在空中

    public System.ServiceModel.Channels.Message SerializeReply(System.ServiceModel.Channels.MessageVersion messageVersion, object[] parameters, object result)
            {
//some code
             }

问题在于,在能够提供这一类服务之后,服务方法参数总是被显示为无效,但在I级的IDisTOPMessageInspector认为,参数是适当的。 我不知道它为什么会发生,我只加上这一信息格式代码,因为空洞的降水等级有可能造成这种情况?

最佳回答

当我们实施<>IDisTOPMessageFormatter接口时,我们通常并不认为,DeserializeRequest是很重要的,因为它没有归还任何数据。 这是误导,因为方法需要做一些事情。

正确通过参数的最容易的方法是使用DisTOPMessageFormatter。 添加到施工者身上。

public class ResponseJsonFormatter : IDispatchMessageFormatter
{
    IDispatchMessageFormatter basicDispatchMessageFormatter;
    OperationDescription Operation;
    public ResponseJsonFormatter(OperationDescription operation, IDispatchMessageFormatter inner)
    {
        this.Operation = operation;
        this.basicDispatchMessageFormatter = inner;
    }

    public void DeserializeRequest(Message message, object[] parameters)
    {
        basicDispatchMessageFormatter.DeserializeRequest(message, parameters);
    }

    public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
    {
        string json=Newtonsoft.Json.JsonConvert.SerializeObject(result);
        byte[] bytes = Encoding.UTF8.GetBytes(json);
        Message replyMessage = Message.CreateMessage(messageVersion, Operation.Messages[1].Action, new RawDataWriter(bytes));
        replyMessage.Properties.Add(WebBodyFormatMessageProperty.Name, new WebBodyFormatMessageProperty(WebContentFormat.Raw));
        return replyMessage;
    }
}

在行为中提出:

public class ClientJsonDateFormatterBehavior : IOperationBehavior
{
    public void AddBindingParameters(OperationDescription operationDescription, BindingParameterCollection bindingParameters)
    {
        // throw new NotImplementedException();
    }

    public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation)
    {
    }

    public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation)
    {
        dispatchOperation.Formatter = new ResponseJsonFormatter(operationDescription, dispatchOperation.Formatter);
    }

    public void Validate(OperationDescription operationDescription)
    {
        // throw new NotImplementedException();
    }
}

https://github.com/pwujczyk/ProductativeTools.Examples.WCFAspects”rel=“nofollow noreferer”

问题回答

如果你在<条码>上不提供自己的逻辑,就不存在违约行为。 DeserializeRequest。 您要么需要参考现有的格式,要么在您的<代码>上人工授权,要么提供自己的逻辑。





相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签