VMware {code} Community
shwu745
Contributor
Contributor

a separate thread causes web service connection failure

My C# program is connecting to VMware VirtualCenter web service with https

protocal. After it estenblishes a web service connection to the server, it

can clone multiple virtaul machines. It works fine if the cloning operation

is taking one by one sequentially in the main thread. If I create multiple

threads to do the task, some thread will cause AuthenticationException with

additional information: The remote certificate is invalid according to the

validation procedure.

Then it throws WebException: The underlying connection was closed: Could not

establish trust relationship for the SSL/TLS secure channel.

My code already implements this:

ServicePointManager.ServerCertificateValidationCallback = new delegate { return true; };

vimService.CookieContainer = new CookieContainer();

I guess the separate threads run in different contexts that cannot maintain

the connection credential. I don't know how to fix this.

Any advise is greatly appreciated.

Reply
0 Kudos
5 Replies
msherman
Enthusiast
Enthusiast

Does each thread login to Virtual Center OR do they share a single login session?

Reply
0 Kudos
shwu745
Contributor
Contributor

They share a login session.

Reply
0 Kudos
msherman
Enthusiast
Enthusiast

I use multiple threads successfully but each thread establishes its own login session. IOW, no session sharing. My code is in java but I'm not sure if that makes any difference.

If you eliminate session sharing please share the results here. I'm curious about C#, thanks.

Reply
0 Kudos
njain
Expert
Expert

There doesn't seem to be any issue in using the same connection in multiple child threads. Can you post your code here?

Reply
0 Kudos
shwu745
Contributor
Contributor

After I set the callback to ServicePointManager.ServerCertificateValidationCallback in each thread, the problem is gone.

Thanks for all replies.

Reply
0 Kudos