开发者

Parameters for webservice call from ASP.NET MVC/jQuery best practice

开发者 https://www.devze.com 2023-01-09 01:57 出处:网络
I need to call a webservice which takes as parameters things like the database name, schema na开发者_如何学Cme, login credentials etc.

I need to call a webservice which takes as parameters things like the database name, schema na开发者_如何学Cme, login credentials etc.

I'd ideally like to call the webservice directly from jQuery, but I feel that these parameters belong in the web config so perhaps I should be calling the webservice indirectly through an ajaxed MVC controller method.

What are peoples opinions on this? Is there an elegant solution?

Edit: It's just occured to me that I'll be exposing the server credentials to the client if I make the call from jQuery, so I guess that isn't an option unless there's a clever trick I don't know about.


Elegance is in the eye of the beholder, but you could institute a token-based system. Users of your service would apply ahead of time to use your service. You would issue a token (a GUID for this example). Each call to the service, the user would include that token as a parameter, or better, part of the request headers. On the server, you could use that token to find out the items needed by that user (database and schema names, login credentials, etc).

Again, elegance is in the eye of the beholder, but a solution like this does address the concern in the question: exposing server credentials to the client.


Jonathan has a good answer, but you could also create some sort of serialized data object that contains all the info you're concerned with, and write it to the client as an encrypted string. pass the string to the web service, and the web service would be able to decrypt and parse as needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消