I'm trying to consume a C# based service, from a C# client.
When I break at the service method call and hover over the preceding username
and password
properties to verify that they are being set, then step over the method, it works fine. When I break at the service method call, and then immediately step over the method call without verifying the username/password, I get object reference not set to an instance of an object
.
The username and password are coming from an app.config
file, and the config values are not changing.
Is this possibly an synchronous processing issue, and the username and password are not getting set in time? I've tried inserting a sleep(5000)
call, which doesn't help. I've updated the service reference many times.
MyService.ServiceClient sc = new MyService.ServiceClient();
sc.ClientCredentials.UserName.UserName ="pinkpanther"; // comes from app.config file
sc.ClientCredentials.UserName.Password = "clouseau"; // comes from app.config file
//open service client/proxy
sc.Open();
Dictionary<int, string> result = new Dictionary<int, string>();
// Sleep(5000); this doesn't seem to help
result = sc.FindVillain("Paris", "Train", "Car3", 4);
success = result.ContainsValue("The villain has been detained.");
sc.Close();