How to consume webservice in javascript - javascript

please tell me how to consume webservice (.net) using javascript.
its SOAP.
Thanks

You use AJAX.
In particular the XMLHttpRequest object.
Look at the jQuery ajax API - it makes AJAX easier to use.

I don't think there is a Javascript library that consumes SOAP out of the box. Dojo offers a lot of functionality in that direction, RPC-calls for example, and is probably the one that comes closest.
IBM did some work there that you might want to check out.
This (including Dojo) is a lot of non-trivial stuff to learn but SOAP is a nasty beast, if you really need to interface to a SOAP service with JS you will have to invest some time.
See:
http://www.ibm.com/developerworks/web/library/wa-dojowebresponse/index.html?ca=drs-
SOAP Requests in Dojo

Both .asmx and .svc (wcf) expose javascript enabled bindings - this is easy to find on the internet.
Example:
http://dotnetbyexample.blogspot.com/2008/02/calling-wcf-service-from-javascript.html
Normally you just append /js to the url of the endpoint and javascript providing a proxy is returned.
This proxy code relies on the ASP.NET AJAX framework, but you can easily use it with any other ajax-enabling framework by using this shim.

Related

Do people still use Ajax for a web applications?

I am programming a full ajax web application and did some research in frameworks for SEO and history tracking. I found this one: http://balupton.github.io/jquery-ajaxy/demo/
It looks great but the last update was 4 years ago. Do people still use something like that? Or is there an easier method out?
Yes, AJAX (XHR) is used all the time in web pages. It is still the primary way that JavaScript in a web page makes an in-page request to a server.
There are now also WebSockets, but AJAX (XHR) and WebSockets have different characteristics for largely different purposes (with some overlap).
There is also now an additional interface fetch() for making Ajax calls which makes some things a lot easier than before and this interface is promise-based rather than just using plain callbacks.
The link that you send seems to be for a jQuery plugin called "Ajaxy". AJAX stands for Asynchronous JavaScript and XML, and is a technology supported by native JavaScript (ECMAScript). Yes, people still use Ajax for web applications. If you have ever submitted a form on a modern website, chances are it uses Ajax in some capacity.

HTTP requests from Sling ESP scripts (Server side JavaScript based on Rhino)

How can I make an HTTP request from a Sling ESP page? Is there something like JQuery or Node's http module that I can use? Or do I have to fall back to Java code?
(Sling ESP Pages are server side JavaScript pages running in the Rhino JavaScript engine)
When sling implements a script language it provides a limited set of bindings to commonly used objects. These are defined here:
http://sling.apache.org/apidocs/sling5/org/apache/sling/api/scripting/SlingBindings.html
In addition, Rhino implements several features to provide integration with java. Such as the Packages variable which contains all the top level java packages, such as java and com.This provides you with a way to interact with java directly from the esp, an example being.
Packages.java.util.Calendar.getInstance()
The details of this java interaction can be found here:
https://developer.mozilla.org/en-US/docs/Rhino/Scripting_Java?redirectlocale=en-US&redirectslug=Scripting_Java
So to answer your question.
No, there isn't a supplied http module for you to use.
Your options are:
Forgo the esp and write a java servlet.
Use the Rhino/Java integration to write the HTTP call in the esp file using the relevant java objects.
Encode the HTTP code into a re-usable OSGi service and use the java integration to access the service
My recommendation would be option 3 as it provides the best code portability, and is the closest to what I would consider the "sling" way of doing things. To access the service you would just use:
var service = sling.getService(Packages.foo.bar.HttpClient.class);
There's no out-of-the box service that you can use to make HTTP requests from a Sling script, but if an HTTP client bundle (such as those from http://hc.apache.org/) makes its classes available you can use them in any Sling script.
As JE Bailey says, that wouldn't be the most convenient thing so you could write an OSGi wrapper service to make this easier. And maybe contribute that to Sling (hint, hint ;-)
If you want to make requests to Sling itself you can use the SlingRequestProcessor service which bypasses HTTP and makes internal requests to Sling directly.

CouchDB AJAX interaction

I'm writing a CouchDB sample. My intention is to write a web app using AJAX and deploy it in the tomcat environment. As I use the CouchDB I would like to know the way to interact with the CouchDB server. However there were few examples but I have few concerns over that.
1) As my application is deployed in a web server is it possible to connect with a CouchDB outside? Many examples uses apps which are deployed in CouchApp or Couch environment itself.
2) If so will it end up with cross domain issues. I found this in here
Connection AJAX, CouchDB and JavaScript
However will this be a problem? Is this the correct way to achieve this?
3) To omit above issues is it possible to use some server side javascript implementation as an example Rhino?
http://www.mozilla.org/rhino/doc.html
4) If I use Rhino above it wont allow many java script libraries to use. How do I interact with CouchDB then? Do I have to invoke native Javascript? Cant I use something like JQuery?
5) What are the best libraries for client side to achieve my goal?
Your help is appreciated.
Thank you
Based on your need to use tomcat, I would just recommend using ektorp (http://ektorp.org/). Just think of ektorp like a jdbc driver. No need to do ajax from the user interface, or no need to use javascript from java in your server.
Ektorp also lets you annotate your java classes with the javascript couchdb needs to make views. see the example here: http://ektorp.org/reference_documentation.html#d100e753
Hope that helps.

Calling a webservice in javascript

I am trying to make a Firefox extension which will use a webservice. I was looking online to find a way to do this. I was wondering if someone could explain what the following objects/methods do:
service.useService(___, ___);
service.<Service Name>.callService();
If there is an alternative that does not include these objects, I would be happy to hear about it.
Thank you very much
It appears you are using IE specific code to call the webservice, and according to this response it may not be supported in newer browsers now:
http://www.eggheadcafe.com/software/aspnet/31984555/you-can-use-xmlhttpreques.aspx
For more on the service.useservice function you may find this page helpful:
http://www.15seconds.com/Issue/040708.htm
If you have control over the web service then you can get it to either reply with a JSON or use a REST web service, as well as a SOAP web service, as javascript can work well with REST, or with a form-based (POST/GET) web service, as opposed to SOAP.

Jquery - Publish and Subscribe?

Is there such a thing as publish and subscribe for use with jquery to send msgs from 1 javascript page to another.. Using the same idea behind ajax publish and subscribe?
I would like to use the pattern for communication between pages, i have been using a javascript framework lately but recently converted back to jquery and would love to continue using this.
Any ideas where i should start? and which implementation to use if more than 1 exists..
Thanks
jQuery is a simple JS toolkit that makes working with the DOM easier.
What you need is something like strophe. It uses XMPP via BOSH. There is a video, where the creator describes it.
Another option is the Bayeux protocol. There are implementations in Dojo and jQuery.
jQuery is just a library providing set of utility functions. It is not a programming language. It is not Ajax.
Ajax is a design pattern. It is not a programming language. It is not a library.
Ajax publish-subscribe is just a more specific design pattern that uses the Ajax pattern.
There is no reason it can't be implemented using jQuery.
I think you're looking for an implementation of the bayeux protocol written in jquery.
A comet plugin that uses the bayeux protocol can be found here
You are trying to use the observer pattern to synch the UI?
I think this should help you
Have a look at the code behind
basically when you click on the check boxes on top the behaviour of the link changes
the code is very small
I love it
Cheers
Check out http://laharsub.codeplex.com. This is an open source project that provides publish/subscribe capability using HTTP APIs and comes with a jQuery extension that provides usable OM for Ajax applications.

Categories