WCF中的basichtpbinding的默认超时是什么

发布于 2025-01-28 04:14:18 字数 3754 浏览 2 评论 0原文

我是WCF的新手,创建了一项服务和一个消费者。正如文档所暗示的那样,默认超时为10分钟的接收时间。

在消费者方面,我试图重现该请求的超时,但是事件25分钟后,它可以毫无疑问。

如果有人可以让我知道我们可以用BasichTTP绑定打开频道的时间是什么?

以下是wcf app.config:

<system.serviceModel>    
      <bindings>
        <basicHttpBinding>
          <binding name="Raj">
            <security mode="Transport">
              <transport clientCredentialType="None" proxyCredentialType="None" realm="">                
              </transport>
            </security>
          </binding>
        </basicHttpBinding>
      </bindings>      
      <behaviors>
            <serviceBehaviors>
                <behavior name="Raj">
                    <serviceMetadata httpsGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>   
        <services>
            <service name="WCF_NewsService.News_Service" behaviorConfiguration="Raj">          
                <host>
                    <baseAddresses>
                        <add baseAddress="https://localhost:8732/Design_Time_Addresses/WCF_NewsService/News_Service/"/>
                    </baseAddresses>
                </host>
                <endpoint address="News_Service" binding="basicHttpBinding" contract="WCF_NewsService.INews_Service" bindingConfiguration="Raj"/>
            </service>
        </services> 
    </system.serviceModel>

消费者代码:

    var myBinding = new BasicHttpBinding();
                myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                myBinding.Security.Transport.ClientCredentialType =
                HttpClientCredentialType.Certificate;

                myBinding.MaxReceivedMessageSize = Int32.MaxValue;
                myBinding.MaxBufferSize = Int32.MaxValue;

BindingParameterCollection bindingParameters = new BindingParameterCollection();

                var address = new EndpointAddress("https:xxxx:8732/Design_Time_Addresses/WCF_NewsService/News_Service/News_Service");
                                
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

                //Client Credentials
                string _thumbPrint = "5AD9BC96AA4D44852D1B97C91C1628C070E3187C";
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, _thumbPrint);

                bindingParameters.Add(clientCredentials);


                var factory = myBinding.BuildChannelFactory<IRequestChannel>(bindingParameters);
                factory.Open();


                var irc = factory.CreateChannel(address);

                // --- Without body
                Message createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/Getnews");
                irc.Open();
                var result = irc.Request(createRequestMessage);

                Thread.Sleep(TimeSpan.FromMinutes(25));


                //--With body
                TOInews tOInews = new TOInews { ID = 125, Body = "this is body test", Header = "This is header test" };
                createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/GetnewsById", tOInews);
                //irc.Open();
                var result1 = irc.Request(createRequestMessage);

I am new to wcf, created a service and a consumer. As documentation suggest, default timeout is 10 minutes for ReceiveTimeout.

In consumer side, i tried to reproduce for timeout for the request but event after 25 minutes it works without breaking.

If someone can let me know what exactly the time we can open a channel with basichttp binding?

Below is the wcf app.config:

<system.serviceModel>    
      <bindings>
        <basicHttpBinding>
          <binding name="Raj">
            <security mode="Transport">
              <transport clientCredentialType="None" proxyCredentialType="None" realm="">                
              </transport>
            </security>
          </binding>
        </basicHttpBinding>
      </bindings>      
      <behaviors>
            <serviceBehaviors>
                <behavior name="Raj">
                    <serviceMetadata httpsGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
        </behaviors>   
        <services>
            <service name="WCF_NewsService.News_Service" behaviorConfiguration="Raj">          
                <host>
                    <baseAddresses>
                        <add baseAddress="https://localhost:8732/Design_Time_Addresses/WCF_NewsService/News_Service/"/>
                    </baseAddresses>
                </host>
                <endpoint address="News_Service" binding="basicHttpBinding" contract="WCF_NewsService.INews_Service" bindingConfiguration="Raj"/>
            </service>
        </services> 
    </system.serviceModel>

Consumer Code:

    var myBinding = new BasicHttpBinding();
                myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
                myBinding.Security.Transport.ClientCredentialType =
                HttpClientCredentialType.Certificate;

                myBinding.MaxReceivedMessageSize = Int32.MaxValue;
                myBinding.MaxBufferSize = Int32.MaxValue;

BindingParameterCollection bindingParameters = new BindingParameterCollection();

                var address = new EndpointAddress("https:xxxx:8732/Design_Time_Addresses/WCF_NewsService/News_Service/News_Service");
                                
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

                //Client Credentials
                string _thumbPrint = "5AD9BC96AA4D44852D1B97C91C1628C070E3187C";
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, _thumbPrint);

                bindingParameters.Add(clientCredentials);


                var factory = myBinding.BuildChannelFactory<IRequestChannel>(bindingParameters);
                factory.Open();


                var irc = factory.CreateChannel(address);

                // --- Without body
                Message createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/Getnews");
                irc.Open();
                var result = irc.Request(createRequestMessage);

                Thread.Sleep(TimeSpan.FromMinutes(25));


                //--With body
                TOInews tOInews = new TOInews { ID = 125, Body = "this is body test", Header = "This is header test" };
                createRequestMessage = Message.CreateMessage(MessageVersion.Soap11, "http://tempuri.org/INews_Service/GetnewsById", tOInews);
                //irc.Open();
                var result1 = irc.Request(createRequestMessage);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2025-02-04 04:14:18

- 由服务框架层使用,用于初始化会话idle超时,该会话超时可以控制一个会话在定时之前可以闲置多长时间。

我没有发现您有ceartivetimeout在配置文件中配置的,您需要配置它。您可以看到下面的代码。
您可以在
如何在超时值上配置超时值绑定
您可以使用 message检查员捕获WCF操作执行时间。参见 /a>针对特定步骤。

 <basicHttpBinding>
          <binding name="Raj" openTimeout="00:10:00"
             closeTimeout="00:10:00"
             sendTimeout="00:10:00"
             receiveTimeout="00:10:00">
            <security mode="Transport">
              <transport clientCredentialType="None" proxyCredentialType="None" realm="">                
              </transport>
            </security>
          </binding>
        </basicHttpBinding>

ReceiveTimeout – used by the Service Framework Layer to initialize the session-idle timeout which controls how long a session can be idle before timing out.

I didn't find that you have ReceiveTimeout configured in the config file, you need to configure it.You can see the code below.
You can check the documentation on how to configure the timeout value on the binding.
You can use Message Inspectors to capture WCF operation execution time. See this post for specific steps.

 <basicHttpBinding>
          <binding name="Raj" openTimeout="00:10:00"
             closeTimeout="00:10:00"
             sendTimeout="00:10:00"
             receiveTimeout="00:10:00">
            <security mode="Transport">
              <transport clientCredentialType="None" proxyCredentialType="None" realm="">                
              </transport>
            </security>
          </binding>
        </basicHttpBinding>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文