vmware-archive / vsphere-automation-sdk-.net

[DEPRECATED] Please see README. C# samples, language bindings, and API reference documentation for vSphere, VMC, and NSX-T using the VMware REST API
MIT License
68 stars 20 forks source link

Session.Create in WebApplication hangs #3

Closed ddNils closed 6 years ago

ddNils commented 7 years ago

Hi there, I got the sample working, but when I try to move/copy the code to my Web-Application, where I want to use it, it just hangs on char[] sessionId = session.Create(); Checking with fiddler, it did send a request to vCenter and got a response including a secret, but the function never returns. Any idea how to solve this?

ddNils commented 7 years ago

I made a demo - project.

  1. Update Reference to SamplesCommon Project
  2. In Test.axps.cs - insert your vCenter url and credentials.

TestVmApi.zip

godefroi commented 7 years ago

I've also seen this behavior in session.Create(). It seems like the API just hangs whenever there's an error.

vinpai commented 6 years ago

This might be an issue in your app. Please troubleshoot your problem to resolve this issue. There are samples you can refer to, to understand how to create a user session in the sources of the repository. If needed, you may take help from the community forums here - https://code.vmware.com/forums/7504/vsphere-automation-sdk-for-.net

godefroi commented 6 years ago

@vinpai I couldn't imagine a less helpful response than yours. You have done a disservice to the community, and if you're an employee of VMware, you've badly represented them to the community.

vinpai commented 6 years ago

Unfortunately, I am not allowed to open zip files in the corporate network. If you can post your code to some repository somewhere, then I can take a look at your code and check if you are missing something. Would you be able to do that ?

vinpai commented 6 years ago

Ok, I wrote a quick webapp sample here which lists vms - https://github.com/vmware/vsphere-automation-sdk-.net/tree/master/vmware/samples/vcenter/vm/list/ListVMsWebApp

Hope that helps resolve your issue.

strefethen commented 6 years ago

@ddNils & @godefroi Does the above sample help resolve the issues you were seeing?

ddNils commented 6 years ago

Yes it does. It works for me. Though I am not sure how.

ddNils commented 6 years ago

I did some additional analysis. It seems the async methods for both LoginByUsernameAndPasswordAsync and ListAsync() are working. The synchronous Methods however do not work for me. In ASP.Net Async Pages are not the default (they have to explicitly marked as async through Async="true") so usually I try to use the synchronous methods.

Thank you very much for the troubleshooting and provided solution @strefethen and @vinpai . I wish the synchronous methods would work better or at least drop better errors. The added sample will probably help in the future.

vinpai commented 6 years ago

I think ASP .NET goes into a deadlock when you use synchronous methods or block on an async method. So, you have to use async all the way. You won't see any errors because your code is deadlocked. There are some blog posts on msdn about this - https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

strefethen commented 6 years ago

@ddNils as Vinod points out I'd be pretty careful using sync methods server side as that's a pretty easy way to bring down your server or at least tie it up so you quickly max out connections.

Glad the example helped.

godefroi commented 6 years ago

I think it's pretty irresponsible to say "it's not safe to use synchronous methods in a server-side context". For most of the history of server-side contexts, synchronous methods were all that were available. If the async methods work, that's fantastic, but if the synchronous ones don't, then that's a bug in the SDK.

strefethen commented 6 years ago

@godefroi hmm, not really sure where that quote is from. Anyhoo, for those following along I'll leave you with Microsoft's advice and suggestions for avoiding "performance devastation" using synchronous server-side web requests.

https://msdn.microsoft.com/en-us/library/aa480507.aspx

Regards

maurizio1976 commented 4 years ago

Hi If this can help, I have verified using the VMware vSphere Automation SDKs that:

If I try to use both examples, in order to have a list of Virtual machines and then launch a VM stop command, reusing the exact same code, the execution just hangs on char[] sessionId = session.Create(); (as it happens for the user "ddNils")

I have verified from the vmware logs (/storage/log/vmware/vpxd/vpxd.log) that I have the following error:

LoginByToken failed: Connection refused: The remote service is not running, OR is overloaded, OR a firewall is rejecting connections.

I was unable to find a solution... I also tried to use only synchronous connections,if anyone could help me....