Setting ClientCredentials fails under loadtest, but not when unittest is run directly

Jun 2, 2010 at 11:18 AM

I created a WCFTest using Visual Studio for my system. The unit test runs without errors, but the loadtest throws exceptions when my unittest tries to set the ClientCredentials on the client.

In the unittest, I essential do this in InitializeTest() in the custom-part of the class for each client I have (there's quite a few):

ClientReferenceCollection.CompanyServiceReference.CompanyServiceClient companyServiceClient = new ClientReferenceCollection.CompanyServiceReference.CompanyServiceClient("WSHttpBinding_ICompanyService");
companyServiceClient.ClientCredentials.UserName.UserName = GetCredentialUserName();
companyServiceClient.ClientCredentials.UserName.Password = GetCredintialPassword();
companyServiceClient.Login(GetLoginUserName() , GetLoginPassword());

Problem starts, when I run a loadtest using this unittest as the only test in the test mix. I get more than 1000 errors, most of the saying this:

Initialization method PrisoversigtWCFTest2.PrisoversigtWCFTest2Tests.InitializeTest threw exception. System.InvalidOperationException:  System.InvalidOperationException: Object is read-only..    view    -   at System.ServiceModel.Security.UserNamePasswordClientCredential.ThrowIfImmutable()
at System.ServiceModel.Security.UserNamePasswordClientCredential.set_UserName(String value)
at WCFLoadTest.TestCredentials.Set(ISecurity client) in D:\Source\EnergiDanmark\Test\WCFLoadTest\WCFLoadTest\TestCredentials.cs:line 69
at WCFLoadTest.TestCredentials.SetCredentials() in D:\Source\EnergiDanmark\Test\WCFLoadTest\WCFLoadTest\TestCredentials.cs:line 49
at PrisoversigtWCFTest2.PrisoversigtWCFTest2Tests.InitializeTest() in D:\Source\EnergiDanmark\Test\WCFLoadTest\WCFLoadTest\PrisoversigtWCFTest2.Custom.cs:line 328

WCFLoadTest is the namespace and WCFLoadTest.TestCredentials is the class, where I acutally set the credentials.

UserName and Password in System.ServiceModel.Security are get and set properties. These should not throw any errors - and besides the unit test works when I run it directly.


It  seems from the documentation (doc) that InvalidOperationException may be called: if the resource set is closed before the method call is made. Is this what happens when the unittest is called repeatedly from the loadtest? How do I avoid this?

Is there an entirely different cause of my problems?


My app.config bindings part are equal to that in the client itself:


        <binding name="WSHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
           receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
           transactionFlow="false" hostNameComparisonMode="StrongWildcard"
           maxBufferPoolSize="5242880" maxReceivedMessageSize="6553600"
           messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
          <readerQuotas maxDepth="32" maxStringContentLength="81920" maxArrayLength="163840"
              maxBytesPerRead="40960" maxNameTableCharCount="163840" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="true" />
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
    <endpoint address="https://.../CompanyService.svc"
        binding="wsHttpBinding" bindingConfiguration="WSHttpBinding"
        contract="CompanyServiceReference.ICompanyService" name="WSHttpBinding_ICompanyService">
          <dns value="localhost" />







Jun 4, 2010 at 8:03 AM

Problem was, that I logged on the services - and used the same logon every time. When running the load test with a single user in a continous load, not errors happens. This leads me to my next question: How to vary test data in my unit test during a WCF Load test run. I'll pose this question under a new headline.