locked
How to pass username and password to wcf sync service RRS feed

  • Question

  • I want to restrict access to my wcf - syncservice (hosted in IIS) with username and password.

    As I found securing a WCF-Service with username / password not so easy, I decided first to build a demo project with a simple CalculatorService (based on the MSDN sample) and apply Username / Password security over wsHttp binding. After some fiddling over certificate I got this working (BTW I found this post really helpful ).

    So now I want to do the same for the sync service. The problem I have is I don't know how to pass the credentials to the service. In my demo project the service is initiated like this:

    Dim calc As New ServiceReferenceLocalhost.CalculatotorServiceClient("wssecure")

    and the credentials are passed like this:

    calc.ClientCredentials.UserName.UserName = "MyUser"
    calc.ClientCredentials.UserName.Password = "Thepassword"

    In my sync project I actually don't initiate the service, when starting the sync, but rather create a new class like this:

    Dim syncAgent As LocalDataCache1SyncAgent = New LocalDataCache1SyncAgent()
    Dim syncStats As Microsoft.Synchronization.Data.SyncStatistics = syncAgent.Synchronize()

    So my question is how and where can I pass in the username / password credentials?

    Thnaks
    Christian
    Thursday, August 25, 2011 3:48 PM

Answers

  • it should go to number 1.

    this is the equivalent of your New ServiceReferenceLocalhost.CalculatotorServiceClient("wssecure")
     above: New ServiceReferenceIIS.LocalDataCache1SyncContractClient("MyBindingContract"))

     

    • Marked as answer by chl-h Tuesday, August 30, 2011 4:38 PM
    Friday, August 26, 2011 3:12 PM

All replies

  • locate in the sync generated code where a ServerSyncProviderProxy is instantiated and you should be able to access the service client there.
    Friday, August 26, 2011 1:11 AM
  • HI JuneT,

    thanks for your help, but I don't know how to do this.

    Searching for "ServerSyncProviderProxy"  in the client project I found two place where ServerSyncProviderProxy is used

    1) Partial Public Class LocalDataCache1SyncAgent
        '
        ' extending/customizing the LocalDataCacheWizard generated code
        ' setting SyncDirection and syncgroups
       
        ' set the Remoteprovider
        ' ServiceReferenceIIS is the reference to the service hosted in IIS
           Me.RemoteProvider = New Microsoft.Synchronization.Data.ServerSyncProviderProxy(New ServiceReferenceIIS.LocalDataCache1SyncContractClient("MyBindingContract"))
        End Sub
    End Class

    2) Wizard generated Sub new
        Public Sub New(ByVal remoteSyncProviderProxy As Object)
            MyBase.New
            Me.InitializeSyncProviders
            Me.InitializeSyncTables
            Me.RemoteProvider = New Microsoft.Synchronization.Data.ServerSyncProviderProxy(remoteSyncProviderProxy)
            Me.OnInitialized()
        End Sub

    I guess this should go somewhere in 1), but could you be a little more precise what the code should look like and if 1) is the right place.

    Thanks
    Christian
    Friday, August 26, 2011 1:26 PM
  • it should go to number 1.

    this is the equivalent of your New ServiceReferenceLocalhost.CalculatotorServiceClient("wssecure")
     above: New ServiceReferenceIIS.LocalDataCache1SyncContractClient("MyBindingContract"))

     

    • Marked as answer by chl-h Tuesday, August 30, 2011 4:38 PM
    Friday, August 26, 2011 3:12 PM