wsDualHttpBinding总是超时,而其他服务按预期工作

时间:2012-01-16 13:11:39

标签: c# wcf timeout duplex wsdualhttpbinding

我目前正在开发多种服务(WCF)以与TFS 2010配合使用。

其中一些使用事件订阅工具,而另一些则通过sharepoint门户,小型wpf应用程序等使用。

我正在开发一个应用程序来管理另一台服务器中的一些东西,比如向服务器发送一个IIS重置请求,我正在使用wsDualHttpBinding,这样我就可以通过回调向所有用户发送进度消息。

但我甚至无法在服务中调用该方法,因为每当通道尝试打开时,无论我的OpenTimeout是什么,都会出现超时异常。

这是我的配置(客户端)

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.net>
        <connectionManagement>
            <add maxconnection="200"   address="*"  />
        </connectionManagement>
    </system.net>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_IReset" closeTimeout="00:01:00"
                    openTimeout="00:02:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="None">
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsDualHttpBinding>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IDeploy" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferPoolSize="1524288" maxReceivedMessageSize="1279748152"
                    messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                    allowCookies="false">
                    <readerQuotas maxDepth="32" maxStringContentLength="81925" maxArrayLength="163848"
                        maxBytesPerRead="9192" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00"
                        enabled="false" />
                    <security mode="None">
                        <transport clientCredentialType="Windows" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://tfsserver:8080/TFSFacade/DeployFacade.svc"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IDeploy"
                contract="DeployFacade.IDeploy" name="WSHttpBinding_IDeploy" />
            <endpoint address="http://tfsserver:8080/DeployService/ResetService.svc"
                binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IReset"
                contract="ResetService.IReset" name="WSDualHttpBinding_IReset" />
        </client>
    </system.serviceModel>
    <appSettings>
        <add key="CopiaLocalRollback" value="true"/>
        <add key="CopiaLocalPublish" value="true"/>
        <add key="ModoDiagnostico" value="false" />
        <add key="TempoTimeout" value="300000" />
    </appSettings>
</configuration>

服务器端:

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true">
            <baseAddressPrefixFilters>
                <add prefix="http://tfsserver:8080"/>
                <add prefix="http://tfsservices:8080"/>
                <add prefix="http://tfsservices:1001"/>
            </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        <bindings>
            <wsDualHttpBinding>
                <binding name="WSDualHttpBinding_ResetService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <reliableSession ordered="true" inactivityTimeout="00:10:00" />
                    <security mode="None">
                        <message clientCredentialType="Windows" negotiateServiceCredential="true" />
                    </security>
                </binding>
            </wsDualHttpBinding>
        </bindings>
        <behaviors>
            <serviceBehaviors>
                <behavior name="EventServiceBehavior">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="true" />
                </behavior>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="EventServiceBehavior" name="DeployService.ResetService">
                <endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_ResetService"
                  contract="DeployService.Contracts.IReset" />
            </service>
        </services>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
    </system.webServer>
</configuration>

合同:

[ServiceContract(SessionMode = SessionMode.Required,
             CallbackContract = typeof(IResetCallback))]
public interface IReset
{
    [OperationContract]
    void ExecutarIISReset();
}

[ServiceContract]
public interface IResetCallback
{
    [OperationContract(IsOneWay = true)]
    void PumpMessage(string message);

    [OperationContract(IsOneWay = true)]
    void PumpResponsiveMessage(ResponsiveMessage message);

    [OperationContract(IsOneWay = true)]
    void PumpLogDeployBEMessage(LogDeployBE message);

    bool Confirmar();

    ServidorModel[] GetServidores();
}

服务(由于问题在到达之前发布,因此不会发布代码):

[AspNetCompatibilityRequirementsAttribute(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)] 
public class ResetService : IReset
{
    //Stuff here
}

在小提琴手中,我在客户端得到了这个:

7 202 HTTP tfsserver:8080 /DeployService/ResetService.svc 0 private resetman.vshost:9000

我多次获得202次,然后时间过去并发生超时

在服务器上运行小提琴,我什么都没有。

可能会发生什么?

编辑:很奇怪,localhost有效。 wsDualHttpBinding需要特殊权限吗?没有在'互联网'上找到任何东西

3 个答案:

答案 0 :(得分:1)

由于您使用的是wsDualHttpBinding,因此您的客户端的服务器都需要在配置中指定的端口上访问。这是它在您的本地计算机上工作的原因,因为您没有任何端口问题。超时与防火墙阻止或您的服务器无法路由回客户端一致。

如果可以通过添加防火墙或端口转发规则轻松访问您的客户端,则wsDualHttpBinding可能仍然适用 - 否则使用wsDualHttpBinding可能并不理想。在这种情况下,您可能需要对消息进行客户端轮询,而不是通过回调接收消息(即客户端通过回调来提取消息而不是通过回调来推送消息)

有关详情,请参阅this帖子。还有this一个。

答案 1 :(得分:0)

尝试

  • ConcurrencyMode = ConcurrencyMode.Reentrant
  • InstanceContextMode = InstanceContextMode.Single
  • 删除SessionMode.Required

关于您的服务行为

答案 2 :(得分:0)

我遇到了同样的问题。 我已经通过在客户端应用程序中使用以下代码将绑定配置传递给服务来解决了这个问题。这将让您了解如何实现目标。它在我的大多数系统中都适用于我,但它仍然在某些系统中提供了超时问题。可能的原因无法绑定端口。

      Service objService = new Service(objClass, "WSDualHttpBinding_ISendChatService");
            WSDualHttpBinding binding = objService.Endpoint.Binding as WSDualHttpBinding;
            int portNumber = FreeTcpPort();
            string hostName = Dns.GetHostName();
            binding.ClientBaseAddress = new Uri("http://"+Dns.GetHostByName(hostName).AddressList[0].ToString()+":" + portNumber + "/");            
            objService.Start(name);


static int FreeTcpPort()
        {
            TcpListener l = new TcpListener(IPAddress.Loopback, 0);
            l.Start();
            int port = ((IPEndPoint)l.LocalEndpoint).Port;
            l.Stop();
            return port;
        }