未调用单向服务方法

时间:2016-09-29 13:06:55

标签: c# wcf

我有一个WCF服务,它在单独的服务上调用单向操作。 我遇到的问题是没有收到单向服务呼叫(没有记录消息)。如果我更改IsOneWay = false,那么它会按预期工作。

该服务托管在IIS中。

代码已被剥离为(我相信的)重要的位。

单程服务:

[ServiceContract]
public interface IOneWayService
{
    [OperationContract(IsOneWay = true)] // changing IsOneWay to false makes everything work as expected.
    void OneWayOperation(int param);
}



[ServiceBehavior()]
public class OneWayService : IOneWayService
{
    public void OneWayOperation(int param)
    {
        Log("OneWayService called.");
    }
}

呼叫发起的服务:​​

[ServiceContract]
public interface ITestService
{
    [OperationContract()]
    OperationResult DoThings();
}

[ServiceBehavior()]
public class TestService : ITestService
{
    public OperationResult DoThings()
    {
        ...
        ...

        if (some condition)
        {
            CallOneWayService();
        }

        return result;

    }

    private void CallOneWayService()
    {
        var cf = new ChannelFactory<IOneWayService>("IOneWayService");
        var channel = cf.CreateChannel();
        channel.OneWayOperation(5);
        cf.Close();
    }

}

web.config:

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <diagnostics wmiProviderEnabled="true">
      <messageLogging logEntireMessage="false" logMalformedMessages="false" logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="false" maxSizeOfMessageToLog="200000"/>
    </diagnostics>
    <bindings>
      <customBinding>

        <binding name="httpsBinaryBinding" closeTimeout="15:00:00" openTimeout="15:00:00" receiveTimeout="15:00:00" sendTimeout="15:00:00">
          <binaryMessageEncoding>
            <readerQuotas maxStringContentLength ="50000000"/>
          </binaryMessageEncoding>
          <httpsTransport authenticationScheme="Basic" maxBufferSize="320000000" maxBufferPoolSize="320000000" maxReceivedMessageSize="320000000" keepAliveEnabled="false" proxyAuthenticationScheme="Basic"/>
        </binding>

        <binding name="httpsBinaryBindingAnon" closeTimeout="15:00:00" openTimeout="15:00:00" receiveTimeout="15:00:00" sendTimeout="15:00:00">
          <binaryMessageEncoding>
            <readerQuotas maxStringContentLength ="50000000"/>
          </binaryMessageEncoding>
          <httpsTransport authenticationScheme="Anonymous" maxBufferSize="320000000" maxBufferPoolSize="320000000" maxReceivedMessageSize="320000000" keepAliveEnabled="false" proxyAuthenticationScheme="Basic"/>
        </binding>
      </customBinding>

    </bindings>

    <client>
      <endpoint address="https://localhost/OneWayService.svc" binding="customBinding" bindingConfiguration="httpsBinaryBindingAnon" contract="IOneWayService" name="IOneWayService" />
    </client>

    <services>

      <service behaviorConfiguration="commonBehavior" name="TestService">
        <endpoint binding="customBinding" bindingConfiguration="httpsBinaryBinding" contract="ITestService"/>
      </service>

      <service behaviorConfiguration="commonBehavior" name="OneWayService">
        <endpoint binding="customBinding" bindingConfiguration="httpsBinaryBindingAnon" contract="IOneWayService"/>
      </service>

    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="commonBehavior">
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <serviceAuthorization serviceAuthorizationManagerType="CustomAuthorizationManager, Common.Auth"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <httpRuntime maxRequestLength="524288"/>
    <customErrors mode="Off"/>
    <roleManager enabled="true"/>
    <authentication mode="Windows"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
  </system.web>
</configuration>

0 个答案:

没有答案