【问题标题】:Can we force WCF server bindings over client bindings我们可以通过客户端绑定强制 WCF 服务器绑定吗
【发布时间】:2015-03-24 10:35:09
【问题描述】:

这是场景,

我们在应用服务器上有 IIS 托管的 Web 服务,现在我们有另一个应用服务器托管代码并通过创建通道和提供超时绑定来调用 IIS 托管的 Web 服务。

现在,无论我们在 WCF 服务器绑定中为超时值设置什么,它们总是会被客户端绑定覆盖。 有什么方法可以强制服务器绑定优先。专门用于超时

因为我们使用的 K2 Workflows 无法添加服务引用,所以我们无法以这种方式添加服务,我们必须将其添加为 dll,然后创建通道,如下面的代码所示,

代码:

 System.Net.NetworkCredential creds = GetCreadentials();
 HttpClientCredentialType credType = creds.httpClientCredentialType;
 BasicHttpBinding binding = new BasicHttpBinding();
 binding.Security.Mode = BasicHttpSecurityMode.Transport;
 binding.Security.Transport.ClientCredentialType = credType;
 EndpointAddress endpoint = new EndpointAddress(Url + "/_vti_bin/FruitFactory/Fruits.svc");
 ChannelFactory<Fruits.Internal.IFruits> factory = new ChannelFactory<Fruits.Internal.IFruits>(binding);
 factory.Credentials.Windows.ClientCredential = creds;
 factory.Credentials.UserName.UserName = creds.UserName;
 factory.Credentials.UserName.Password = creds.Password;
 Fruits.Internal.IFruits proxy = factory.CreateChannel(endpoint);
 proxy.GetFruitCratesData(true);

编辑

我知道如何在客户端代码中使用超时绑定,但这不是我想要的,我不希望我的服务使用客户端绑定。

【问题讨论】:

    标签: c# asp.net wcf iis


    【解决方案1】:

    您可以强制客户端使用服务器的设置。但是你可以在代码中设置超时时间

    binding.OpenTimeout = new TimeSpan(0, 10, 0);
    binding.CloseTimeout = new TimeSpan(0, 10, 0);
    binding.SendTimeout = new TimeSpan(0, 10, 0);
    

    【讨论】:

    • 这就是我不希望发生的事情,我不想让客户有权在代码中添加超时。
    • 您不能强制客户端使用大于客户端配置的超时时间。整个通信始终使用最短的超时时间。
    猜你喜欢
    • 1970-01-01
    • 2023-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 2012-04-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多