Case:
First I will explain current situation with config files then I will ask my question: We have two WCF Duplex Services (OrdinaryCustomerService,PremiumCustomerService). These two services are Identical and contain only one operation "DoOperation" and reply to Client through Callback named (ICustomerCallBack) which contains only one operation (Notify). The Source Code :
[ServiceContract(CallbackContract = typeof (ICustomerCallBack))]
public interface ICustomer
{
[OperationContract]
[FaultContract(typeof (FaultException))]
void DoOperation();
}
public interface ICustomerCallBack
{
[OperationContract(IsOneWay = true)]
void Notify(String message);
}
We also have Routing Service (CustomerService) which forward the incoming message either to OrdinaryCustomerService or to PremiumCustomerService and this selection is based on Custom Filter in Routing Table. The Routing Service has two Custom Filters HiBillingFilter and LowBillingFilter the Filter checks if the caller identity is matched with stored one and then check caller rank and there is three options : First: caller ID matches with stored and rank matches with stored then the filter must forward the message to the specified server. Second: caller ID matched with stored but rank doesn't matches then the filter must check next filter Third: caller ID doesn't match then the Match method must close connection gracefully and send FaulException with Message that the user cannot connect and here is our issue. I will show you WebConfig for hosting App First then I'll explain the issue
The WebConfig for Hosting Application is:
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:808/OrdinaryCustomerService/" binding="netTcpBinding" contract="*" name="CustomerServiceLibrary_OrdinaryCustomerService" />
<endpoint address="net.tcp://localhost:807/PremiumCustomerService" binding="netTcpBinding" contract="*" name="CustomerServiceLibrary_PremiumCustomerService" />
</client>
<services>
<service name="OrdinaryCustomerService.OrdinaryCustomerService" behaviorConfiguration="normalServiceBehavior" >
<endpoint address="" binding="netTcpBinding" contract="CustomerContract.ICustomer" bindingConfiguration="NetTcpBinding_ICustomer">
<identity>
<dns value="xxx" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:808/OrdinaryCustomerService/" />
</baseAddresses>
</host>
</service>
<service name="PremiumCustomerService.PremiumCustomerService" behaviorConfiguration="normalServiceBehavior" >
<endpoint address="" binding="netTcpBinding" contract="CustomerContract.ICustomer" bindingConfiguration="NetTcpBinding_ICustomer">
<identity>
<dns value="xxx" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:807/PremiumCustomerService" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="RoutingServiceBehavior" name="System.ServiceModel.Routing.RoutingService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:809/CustomerService/" />
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="System.ServiceModel.Routing.IDuplexSessionRouter" name="RoutingServiceEndpoint" bindingConfiguration="NetTcpBinding_ICustomer">
<identity>
<dns value="xxx" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RoutingServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<routing filterTableName="routingRules" routeOnHeadersOnly="False" />
</behavior>
<behavior name="normalServiceBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<routing>
<namespaceTable>
<add prefix="cc" namespace="http://ift.tt/1o01lnL; />
</namespaceTable>
<filters>
<filter name="HiBillingFilter" filterType="Custom" customType="CustomerService.HiBillingFilter, CustomerService"/>
<filter name="LowBillingFilter" filterType="Custom" customType="CustomerService.LowBillingFilter, CustomerService"/>
<filter name="MatchAll" filterType="MatchAll" />
</filters>
<filterTables>
<filterTable name="routingRules">
<add filterName="HiBillingFilter" endpointName="CustomerServiceLibrary_PremiumCustomerService" priority="2"/>
<add filterName="LowBillingFilter" endpointName="CustomerServiceLibrary_OrdinaryCustomerService" priority="1"/>
<add filterName="MatchAll" endpointName="CustomerServiceLibrary_OrdinaryCustomerService" priority="0" />
</filterTable>
</filterTables>
<backupLists>
<backupList name="CustomerBackupList">
<add endpointName="CustomerServiceLibrary_OrdinaryCustomerService" />
</backupList>
</backupLists>
</routing>
</system.serviceModel>
Question:
How to make filter reply with FaultException instead of forward the message to service? I tried to use :
OperationContext.Current.RequestContext.Reply(newreply);
but the RequestContext is always null.
And I also tried to use the
OperationContext.Current.Channel
and
IClientChannel channel = OperationContext.Current.GetCallbackChannel<IClientChannel>()
but I also couldn't send the reply to client.
Please help me with this problem and thank you in advance.
No comments:
Post a Comment