Frage

Ich habe einen WCF -Protokollierungsdienst, der über MSMQ betrieben wird. Die Elemente sind in einer SQL Server 2005 -Datenbank protokolliert. Jede Funktionen ordnungsgemäß, wenn sie außerhalb eines TransaktionenScope verwendet werden. Wenn der Aufruf in einer Transactionscope -Instanz verwendet wird, wird die Transaktion immer abgebrochen. Message = "Die Transaktion hat abgebrochen".

Was muss ich tun, um diesen Anruf in eine Transaktion zu arbeiten? Ist es überhaupt möglich. Ich habe gelesen, dass eine Client -Transaktion über eine Servicegrenze fließt, die Bindung den Transaktionsfluss unterstützen muss, was die Bindungen sofort auf NetnamedPipeBinding, Nettcpbinding, Wshttpbinding, WsDualhttpbinding und WSFederationhttpbinding begrenzt.

War es hilfreich?

Lösung

I'm not intimately knowledgeable about MSMQ, but there's a really good blog post series by Tom Hollander on MSMQ, IIS and WCF: Getting them to play nicely - in part 3 which is the link provided Tom talks about getting transactional.

MSMQ can be transactional - or not. And in WCF, you can decorate both the service contract as well as individual operation contracts (methods) with transaction-related attributes, such as whether to allow, disallow, or require a transaction context.

As far as I understand, in your setup, you don't want the MSMQ part to be transactional - but you should be able to use it even if an ambient transaction is present. In this case, you need to add the TransactionFlow="ALlowed" to your operation contract like this:

[ServiceContract]
public interface ILoggingService
{
  [OperationContract]
  [TransactionFlow(TransactionFlowOption.Allowed)]
  void LogData(......);
}

That should do it!

Marc

Andere Tipps

Sorry for the needless question...

I have solved my problem. I needed to place

[TransactionFlow(TransactionFlowOption.Allowed)]

on the operation in the service contract and then

[OperationBehavior(TransactionScopeRequired=true)] 

on the implementation of the contract (the service itself).

Works a treat.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top