【问题标题】:WCF: message not received (array length?)WCF:未收到消息(数组长度?)
【发布时间】:2013-09-11 15:23:56
【问题描述】:

我有一个 WCF 服务,其方法接受一个数组(Frame 类型)。数组中的每个元素都包含一个小的元素数组(Shape 类型),其中每个元素都有两个属性。所以,一切正常。但是现在我有一条从客户端到服务器的消息,它由一个 28 帧的数组组成。使用 Wireshark,我看到消息传输正确。但在我的 .NET WCF 服务中,我没有接到电话。但为什么?绑定和阅读器配额设置为 5MB,应该足够了。

绑定配置:

    <bindings>
        <webHttpBinding>
            <binding name="default" transferMode="Streamed" maxReceivedMessageSize="5000000" maxBufferSize="5000000" maxBufferPoolSize="5000000">
                <readerQuotas maxStringContentLength="5000000" maxArrayLength="5000000" />
            </binding>
        </webHttpBinding>
    </bindings>

WCF 服务定义:

[ServiceContract]
public interface IEditor
{
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "/WriteFrames", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    void WriteFrames(Frame[] frames, int animationSpeed);
}

类型说明:

  1. 类型:框架
    • 数组:形状
      • 形状 1
      • 形状 2
      • ...
  2. 类型:形状
    • 数组:点
      • 第 1 点
      • 第 2 点
      • ...
  3. 类型:点
    • X

该服务作为单例托管。请参阅静态 Create 方法。

sealed class EditorHost : ServiceHost
{
    public EditorHost()
        : base(typeof(Editor))
    {
    }

    public EditorHost(params Uri[] baseAddresses)
        : base(typeof(Editor), baseAddresses)
    {
    }

    public EditorHost(Editor singleton, params Uri[] baseAddresses)
        : base(singleton, baseAddresses)
    {
    }

    internal static EditorHost Create(out Editor editor, int port = 8732)
    {
        var uri = new Uri(string.Format("http://localhost:{0}/", port));
        editor = new Editor();
        var host = new EditorHost(editor, uri);
        return host;
    }
}

【问题讨论】:

    标签: c# arrays json wcf


    【解决方案1】:

    我在this post 中发现了问题。我的绑定配置是正确的,但它没有正确应用到我的端点。在端点上使用属性 bindingConfiguration 有效。

    我使用来自Colasoft 的网络嗅探器发现了问题,然后它告诉我包最后说“太长”。因此 JSON 内容被破坏(中断)并且没有正确反序列化。我只是想知道.NET 没有抛出任何异常。

            <webHttpBinding>
                <binding name="webDefault" transferMode="Streamed" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
                    <readerQuotas
                        maxStringContentLength="2147483647"
                        maxArrayLength="2147483647"
                         maxDepth="2147483647"
                         maxBytesPerRead="2147483647"
                         maxNameTableCharCount="2147483647"
                        />
                </binding>
            </webHttpBinding>
    
            <service name="WebService.EditorService.Editor" behaviorConfiguration="BehConfig">
                <endpoint address="/JSON" binding="webHttpBinding" bindingConfiguration="webDefault" contract="WebService.EditorService.IEditor" behaviorConfiguration="web" />
            </service>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 2012-05-13
      • 2018-05-15
      • 2014-02-17
      • 2012-12-13
      • 1970-01-01
      相关资源
      最近更新 更多