A few weeks back I was working on sync framework issue which i found worth blogging, we were using Win form application that uploads the data using ado.net sync framework v2.0, on the server side there is a WCF application to which the data is uploaded.
The data is successfully sent to the server and synced into the server database. But, when the client ends the session, it gets the error below:
‘The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state’. The security context token is either bad or expired
The data is successfully loaded into the server, sync succeeds, but the client fails to gracefully close the session and does not report the completion of the sync activity.
We don’t get this error if we disable the batching on the DbSyncProvider .
Here is what we saw :
If Batching is enabled-
· When there is no data, the Sync over WCF happens fine
· But when there is data then the Sync fails with error – ‘invalid or expired security context token’
If Batching is disabled, Data Sync happens correctly
So what if I want the batching enabled?
Here is what we found as a resolution after detailed investigation:
We Moved ChangeBatch directory out of the WCF IIS Service directory. It resolved the “invalid or expired security context token” error.
And the reason is, IIS automatically refreshes application service if it detects essential or enough changes in the virtual directory. The sync session creates and deletes a number of batch files and triggers IIS to close and re-open the WCF Service after finishing the last ApplyChanges() call.
Author : Lalitesh (MSFT), SQL Developer Engineer , Microsoft and Naresh(MSFT), SQL Developer Technical Lead, Microsoft
Reviewed by : Ambuj(MSFT), SQL Developer Technical Lead, Microsoft