Getting "Object is read only" error when setting ClientCredentials in WCF
        Posted  
        
            by Paul Mrozowski
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Paul Mrozowski
        
        
        
        Published on 2008-10-13T20:57:31Z
        Indexed on 
            2010/04/12
            15:03 UTC
        
        
        Read the original article
        Hit count: 597
        
visual-studio
|wcf
I have a proxy object generated by Visual Studio (client side) named ServerClient. I am attempting to set ClientCredentials.UserName.UserName/Password before opening up a new connection using this code:
InstanceContext context = new InstanceContext(this);
m_client = new ServerClient(context);
m_client.ClientCredentials.UserName.UserName = "Sample";
As soon as the code hits the UserName line it fails with an "Object is read-only" error. I know this can happen if the connection is already open or faulted, but at this point I haven't called context.Open() yet.
I have configured the Bindings (which uses netTcpBinding) to use Message as it's security mode, and MessageClientCredentialType is set to UserName.
Any ideas?
© Stack Overflow or respective owner