简体   繁体   中英

Calling WCF Service from JavaScript

I have a WCF webservice developed with .NET 4.0 which I need to be called by a Javascript client. I have been searching online for the best binding to use to make this possible. Most answers seems to point towards webhttp, but I am concerned as this is one of the lest secure bindings. What is the best way to configure this?

As per my experience and understanding of "invoking wcf service from client side using jquery", i would say:

You can use either of webhttp or basichttp binding if need to invoke using jquery/javascript (surely basichttp better choice over webhttp here).

One person even wrote an article on codeproject where mentioned that using jquery one can even invoke wshttp bidning based wcf, I have not tried it myself, so not sure about it but if you need to expose your service with wshttp, then can refer this link on CP: http://www.codeproject.com/Articles/311908/Calling-WCF-service-exposed-with-different-binding

In my opinion i would say: if there is no business need to expose service as rest one, then don't go for webhttp, Again if your client app is NOT a .net app and if there is no need to have security in place, then you can avoid wshttp totally, so per this i would say go for basichttp bidning, where you get interoperable service and can even add security in future, if needed.

Quick testing your WCF webservice you can install "Advance REST client", it's available for Chrome/Firefox. In order to integrate with your JS client app, you can use jQuery http get post depending upon your WCF verb. Alternatively, you can also use Angular.JS for the same, eg, $http.get

For security you can secure your service endpoints in .net

Take a look at this page which specify different security configurations you can use in wcf.

What is your javascript client? is it running in browser?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM