简体   繁体   English

WCF服务未正确绑定

[英]WCF Service doesn't take the right binding

I'm already sorry for asking the same kind of questions over and over. 我已经为一遍又一遍地问同样的问题而感到抱歉。 We're running a WCF service with a WPF client application and want to transfer large data from the client application over the WCF service to a database, nothing special about this setting. 我们正在使用WPF客户端应用程序运行WCF服务,并希望通过WCF服务将大数据从客户端应用程序传输到数据库,此设置没有什么特别的。 Now, of course, when trying to upload data (over 16kb) as a byte array I receive the usual 'max array length quota has been exceeded' which brought me to configuring my web.config on the server-side as well as my app.config on the client side to include higher readerquotas for everything. 现在,当然,当尝试以字节数组形式上传数据(超过16kb)时,我收到通常的“已超出最大数组长度配额”,这使我在服务器端以及我的应用程序上配置了web.config客户端上的.config包含更高的读者配额。

Now, since this was treated quiet often on stackoverflow, I did a lot of research and finally came to the result of tracking down my service binding via 现在,由于经常在stackoverflow上将其视为安静,因此我做了很多研究,最后得出了通过跟踪服务绑定的结果。

Trace.WriteLine(OperationContext.Current.EndpointDispatcher.ChannelDispatcher.BindingName)

which gave me http://tempuri.org/:BasicHttpBinding (although other namespaces are configured) and which raise the question whether or not my custom binding is applicated or not. 这给了我http://tempuri.org/:BasicHttpBinding (尽管配置了其他命名空间),并引发了一个问题,即是否应用了我的自定义绑定。 Would you please a have look at the part of code of my web.config (service-side) 您能否看一下我的web.config代码的一部分(服务端)

<system.serviceModel>


<behaviors>

  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483646" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IDataController" closeTimeout="00:05:00"
      openTimeout="00:05:00" receiveTimeout="00:05:00" sendTimeout="00:05:00"
      maxBufferPoolSize="500000000" maxBufferSize="500000000" maxReceivedMessageSize="500000000" messageEncoding="Mtom">
      <readerQuotas maxDepth="500000000" maxStringContentLength="500000000"
        maxArrayLength="500000000" maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
    </binding>

    </basicHttpBinding>
</bindings>

<services>
  <service name="DataController">
    <endpoint address="http://vs0092:81/DataController/DataController.svc"  
              binding="basicHttpBinding"
              bindingConfiguration="BasicHttpBinding_IDataController"

              contract="SMS.RC.IDataController" />
    <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

  </service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />


</system.serviceModel>

Now the client side app.config looks like this 现在客户端app.config看起来像这样

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IDataController"
               openTimeout="00:05:00"
               sendTimeout="00:05:00"
               receiveTimeout="00:05:00"
               closeTimeout="00:05:00"
               maxBufferPoolSize="500000000"
               maxReceivedMessageSize="500000000"
               maxBufferSize="500000000">
        <readerQuotas maxDepth="500000000"
                      maxStringContentLength="500000000"
                      maxArrayLength="500000000"
                      maxBytesPerRead="500000000"
                      maxNameTableCharCount="500000000" />

      </binding>
     </basicHttpBinding>
     </bindings>
    <client>
        <endpoint address="http://vs0092:81/DataController/DataController.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataController"
            contract="FBCDataController.IDataController" name="BasicHttpBinding_IDataController" />
    </client>
</system.serviceModel>

So do you see the problem? 那你看到问题了吗? I don't and I've been really put a lot efforts in solving this question but I guess at this point my WCF know how is just to small. 我没有,而且我在解决这个问题上确实付出了很多努力,但我想目前我的WCF知道如何做到这一点很小。 Why is the binding of the service not applicated?? 为什么不应用服务绑定? Could it be a question of implementing a good ServiceBehavior? 实施良好的ServiceBehavior可能是一个问题吗? Is there a way of looking up the correct name of the service? 有没有一种方法可以查询服务的正确名称? (which I read has to be the full name with namespace included) (我读的必须是全名,包括名称空间)

Thanks a lot, Tom 非常感谢,汤姆

I don't see any obvious problems with your configuration but here are a few pointers: 我看不到您的配置有任何明显的问题,但是这里有一些提示:

You may want to review/change your configurations by using the WCF configuration tool - it lists all available settings, not just the ones that are in the config file by default. 您可能想使用WCF配置工具查看/更改配置-它列出了所有可用设置,而不仅仅是默认情况下配置文件中的设置。 It's on the Tools menu. 在“工具”菜单上。 I find that if I open it from there first, then immediately close it, I can then right-click on a config in Solution Explorer to run it for that specific file. 我发现,如果我首先从那里打开它,然后立即将其关闭,则可以在解决方案资源管理器中右键单击一个配置以针对该特定文件运行它。 Not sure why that extra step is needed for me - your mileage may vary. 不知道为什么我需要采取额外的步骤-您的里程可能会有所不同。

From within the WCF config tool you can also enable tracing and logging - WCF traces and logs usually have much better information about what goes wrong when something does than the exception message by itself. 在WCF配置工具中,您还可以启用跟踪和日志记录-与异常消息本身相比,WCF跟踪和日志通常可以更好地了解发生某些错误时的错误信息。

Finally, for messages this large you may want to consider using a streaming model instead. 最后,对于这么大的消息,您可能需要考虑使用流模型。 Look for a working WCF streaming example and go from there. 寻找一个可行的WCF流媒体示例,然后从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM