Tuesday, November 18, 2008

WCF MSMQ Integration Binding Configurations


WCF service is just as normal:



public interface IGMOWCFTrace
{
[OperationContract(IsOneWay = true, Action = "*")]
void WriteLine(MsmqMessage gmoLogMsmq);
}



host = new ServiceHost(typeof(GMO.XIPCommon.Logging.GMOWCFTraceService));



and Service config need to specify msmq and exactlyOnce=false for non-transactinal queue.



<system.serviceModel>
<services>
<service
name="GMO.XIPCommon.Logging.GMOWCFTraceService" >
<endpoint address="msmq.formatname:DIRECT=OS:.\private$\Logging"
binding="msmqIntegrationBinding"
bindingConfiguration="LoggingProcessorBinding"
contract="GMO.XIPCommon.Logging.IGMOWCFTrace">
</endpoint>
</service>
</services>
<bindings>
<msmqIntegrationBinding>
<binding name="LoggingProcessorBinding" exactlyOnce="false" >
<security mode="None" />
</binding>
</msmqIntegrationBinding>
</bindings>
</system.serviceModel>




WCF client has MSMQ code and optionally WCF Code:



public override void WriteLine(object o)
{
Message msg = new Message();
msg.Body = (GMO.XIPCommon.Logging.GMO_LOG_DataContract)o;
loggingQueue.Send(msg);
}



Note Client Configuration can optionally have WCF serviceModel to hint WCF services start processing. This is not absolutely needed but some of my test showed logging
stuck in MSMQ until a call is made to WCF Services:



<system.serviceModel>
<client>
<endpoint name="LoggingEndpoint"
address="msmq.formatname:DIRECT=OS:.\private$\Logging"
binding="msmqIntegrationBinding"
bindingConfiguration="LoggingBinding"
contract="GMO.XIPCommon.Logging.IGMOWCFTrace">
</endpoint>
</client>

<bindings>
<msmqIntegrationBinding>
<binding name="LoggingBinding" exactlyOnce="false" >
<security mode="None" />
</binding>
</msmqIntegrationBinding>
</bindings>
</system.serviceModel>



In other words, MSMQ integration need both MSMQ Code and WCF client code.


No comments: