Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何通过编程获得WCF绑定的详细信息_Asp.net_Wcf_Wcf Binding - Fatal编程技术网

Asp.net 如何通过编程获得WCF绑定的详细信息

Asp.net 如何通过编程获得WCF绑定的详细信息,asp.net,wcf,wcf-binding,Asp.net,Wcf,Wcf Binding,我已经编写了一个带有WCF后端的ASP.Net网站。该网站的功能之一是允许用户下载从WCF服务流式传输的文件 ASP.Net项目中的web.config文件在绑定中设置了最大文件大小(maxBufferSize和maxReceivedMessageSize)。若要阻止用户下载超过此大小的文件,我需要对照web.config文件中的最大文件大小检查文件大小,如何执行此操作 我已经了解了binding.CreateBindingElements()的情况,但我不确定首先如何获取绑定实例 编辑:绑定详

我已经编写了一个带有WCF后端的ASP.Net网站。该网站的功能之一是允许用户下载从WCF服务流式传输的文件

ASP.Net项目中的web.config文件在绑定中设置了最大文件大小(maxBufferSize和maxReceivedMessageSize)。若要阻止用户下载超过此大小的文件,我需要对照web.config文件中的最大文件大小检查文件大小,如何执行此操作

我已经了解了binding.CreateBindingElements()的情况,但我不确定首先如何获取绑定实例

编辑:绑定详细信息如下:

<binding name="BasicHttpBinding_IC_Server" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">

提高缓冲区大小可以解决这个问题,但我宁愿通过将文件大小与maxBufferSize进行比较来避免这个错误。

最终我自己解决了这个问题

其中,
sr
是服务参考:

System.ServiceModel.Description.ServiceEndpoint endpoint = sr.Endpoint;
System.ServiceModel.Channels.BindingElementCollection elements =
    Endpoint.Binding.CreateBindingElements();
long size = elements.Find<System.ServiceModel.Channels.TransportBindingElement>().MaxReceivedMessageSize; 
System.ServiceModel.Description.ServiceEndpoint=sr.endpoint;
System.ServiceModel.Channel.BindingElement集合元素=
Endpoint.Binding.CreateBindingElements();
long size=elements.Find().MaxReceivedMessageSize;

请澄清,您的文件实际上是“流式传输”的还是刚刚下载的?在流式处理中,我认为约束设置更多地围绕块的大小,而不是文件本身。您可以发布您的OperationContract定义吗?另外,听起来您希望网站访问应用程序中其他地方公开的端点的信息。这不会是你在WCF服务本身的上下文中执行检查的事情,对吗?@Rich-谢谢你的评论,我在我的帖子中添加了一些细节,应该可以回答你的问题。
System.ServiceModel.Description.ServiceEndpoint endpoint = sr.Endpoint;
System.ServiceModel.Channels.BindingElementCollection elements =
    Endpoint.Binding.CreateBindingElements();
long size = elements.Find<System.ServiceModel.Channels.TransportBindingElement>().MaxReceivedMessageSize;