Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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
C# WCF异步方法不总是被调用_C#_.net_Wcf_Asynchronous - Fatal编程技术网

C# WCF异步方法不总是被调用

C# WCF异步方法不总是被调用,c#,.net,wcf,asynchronous,C#,.net,Wcf,Asynchronous,我有三个相同的WCF自托管Net.Tcp服务在三台不同的机器上侦听。在我的客户机上,我为每个服务器创建一个任务,其中包含我的WCF客户机的一个实例(每个服务器一个实例),最终异步调用每个服务上的一个WCF操作 我注意到服务呼叫不可靠。也就是说,在某些情况下,通话有效,而在另一些情况下则无效。每次运行都会在三台机器中的不同机器上失败,但总是三台机器中的一台,而不是两台或全部三台 我在所有服务器和客户端上启用了详细的WCF跟踪。对于发生故障的服务器,服务器端没有证据表明曾经建立过连接。在客户端,服务

我有三个相同的WCF自托管Net.Tcp服务在三台不同的机器上侦听。在我的客户机上,我为每个服务器创建一个任务,其中包含我的WCF客户机的一个实例(每个服务器一个实例),最终异步调用每个服务上的一个WCF操作

我注意到服务呼叫不可靠。也就是说,在某些情况下,通话有效,而在另一些情况下则无效。每次运行都会在三台机器中的不同机器上失败,但总是三台机器中的一台,而不是两台或全部三台

我在所有服务器和客户端上启用了详细的WCF跟踪。对于发生故障的服务器,服务器端没有证据表明曾经建立过连接。在客户端,服务跟踪日志甚至不指示进行了连接尝试。我的控制台调试日志显示代码确实被命中

下面是正在调用的异步方法:

public async Task InstallAsync(string installerPath, string commandLine)
{
    Debug.WriteLine("[{0}] InstallerAgentServiceClient.InstallAsync({1}, {2})", _endpointAddress,
        installerPath, commandLine);

    try
    {
        _proxy = new InstallerAgentService.InstallerAgentServiceClient(
            new InstanceContext(this), // assign callback class instance
            new NetTcpBinding(),
            _endpointAddress);

        _proxy.InnerChannel.Faulted +=
            (sender, args) =>
            {
                throw new Exception(string.Format("Inner channel faulted for {0}!", _endpointAddress));
            };

        _proxy.InnerChannel.Closed +=
            (sender, args) =>
            {
                throw new Exception(string.Format("Inner channel closed for {0}!", _endpointAddress));
            };

        await _proxy.InstallAsync(installerPath, commandLine);  // <=== *Sometimes* this doesn't work, and never throws an exception
    }
    catch (CommunicationException ce)
    {
        Logger.ErrorException(ce.Message, ce);
        _proxy.Abort();
    }
    catch (TimeoutException te)
    {
        Logger.ErrorException(te.Message, te);
        _proxy.Abort();
    }
    catch (Exception e)
    {
        Logger.ErrorException(e.Message, e);
        _proxy.Abort();
        throw;
    }
}
公共异步任务InstallAsync(字符串installerPath,字符串命令行) { Debug.WriteLine(“[{0}]InstallerAgentServiceClient.InstallAsync({1},{2})”,_endpointAddress, 安装路径,命令行); 尝试 { _代理=新的InstallerAgentService.InstallerAgentServiceClient( new InstanceContext(this),//分配回调类实例 新的NetTcpBinding(), _端点地址); _proxy.InnerChannel.Faulted+= (发送方,args)=> { 抛出新异常(string.Format(“内部通道因{0}而出错!”,_endpointAddress)); }; _proxy.InnerChannel.Closed+= (发送方,args)=> { 抛出新异常(string.Format(“为{0}关闭的内部通道!”,_endpointAddress)); };
wait _proxy.InstallAsync(installerPath,commandLine);//它会引发异常吗?你有异常吗?它从不引发异常。你有没有可能不
等待
InstallAsync
调用它的某个地方的结果?还有,把
Debug.WriteLine(新的{SynchronizationContext.Current})
await
之前,它显示了什么?此外,在
await
之后放置一个
Debug.Assert(false)
,它是否被命中?第一次调试显示了几个
{Current=}
和Assert(false)在
wait
之后被命中。有趣的是,我的第一个也是唯一一个web服务调用是
InstallAsync()
。如果我在每次构造客户端代理之后添加
Heartbeat()
同步调用,所有实例都会调用
InstallAsync()
方法很好。我想知道异步WCF是否存在缺陷或文档不完整的警告,其中必须先进行同步调用。
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <appSettings>
    ...
  </appSettings>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Verbose">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="c:\logs\Cmc.Installer.App.svclog" />
    </sharedListeners>
    <trace autoflush="true">
      <listeners>
        <add name="logListener" type="System.Diagnostics.TextWriterTraceListener"
             initializeData="c:\logs\Cmc.Installer.App.log.txt" />
        <add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>

  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
                      logEntireMessage="true"
                      logMessagesAtServiceLevel="true"
                      logMalformedMessages="true"
                      logMessagesAtTransportLevel="true"
                      logKnownPii="true">
      </messageLogging>
    </diagnostics>
    <bindings>
      <netTcpBinding>
        <binding name="NetTcpBinding_IInstallerAgentService"
                 openTimeout="00:00:30"
                 sendTimeout="01:00:00"
                 closeTimeout="00:00:30"
                 receiveTimeout="10675199.02:48:05.4775807">
        </binding>  
      </netTcpBinding>
    </bindings>
    <client>
      <endpoint address=""
        binding="netTcpBinding" bindingConfiguration="NetTcpBinding_IInstallerAgentService"
        contract="InstallerAgentService.IInstallerAgentService" name="NetTcpBinding_IInstallerAgentService">
        <identity>
          <userPrincipalName value="c2kbuild@mydomain.com" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>
<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <appSettings>
    <add key="MsiLog" value="C:\logs\Cmc.Installer.Agent.MSI.log.txt" />
  </appSettings>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel"
              switchValue="Verbose, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging"
              switchValue="Verbose">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="c:\logs\Cmc.Installer.Agent.svclog" />
    </sharedListeners>
    <trace autoflush="true">
      <listeners>
        <add name="logListener" type="System.Diagnostics.TextWriterTraceListener"
             initializeData="c:\logs\Cmc.Installer.Agent.Console.log.txt" />
        <add name="consoleListener" type="System.Diagnostics.ConsoleTraceListener" />
      </listeners>
    </trace>
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging maxMessagesToLog="30000"
                      logEntireMessage="true"
                      logMessagesAtServiceLevel="true"
                      logMalformedMessages="true"
                      logMessagesAtTransportLevel="true">
      </messageLogging>
    </diagnostics>
    <behaviors>
      <serviceBehaviors>
        <behavior name="mexBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <netTcpBinding>
        <binding openTimeout="00:00:30"
                 sendTimeout="01:00:00"
                 closeTimeout="00:00:30"
                 receiveTimeout="10675199.02:48:05.4775807">
        </binding>
      </netTcpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="mexBehavior" name="Cmc.Installer.Agent.InstallerAgentService">
        <endpoint address=""
                  binding="netTcpBinding"
                  bindingNamespace="http://mydomain.com/installer/2014/05"
                  contract="Cmc.Installer.Agent.IInstallerAgentService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://*:8890" />
            <add baseAddress="net.tcp://*:8889" />
          </baseAddresses>
        </host>
      </service>
    </services>
  </system.serviceModel>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
</configuration>