I have designed a web based calculator. But I want to have this calculator run on a web service(WSDL). I'm using C# and Javascript behind the back of my website. So could you help me where to add the WSDL descriptions in code and where? If required I can put my code here. Best regards.
1 Answer
You need to make a request to the webservice, you don't need to put WSDL into javascript.
Calling a webservice is a request like any other request, you can use AJAX with JQuery for example:
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebService.asmx/WebMethodName",
data: "{}",
dataType: "json"
});
Example from: http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/
7 Comments
user734577
Thank you for your reply. Sorry I'm quite new to this web service operations. So will my code look like this after I add the request? $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "WebService.asmx/WebMethodName", data: "{}", dataType: "json" }); //rest of the javascript code goes here...
Bruno Costa
If you want to use web service with javascript (in this case jquery). Check the link I put there. If you want to use the webservice from the code of you website, you should add a web reference to that. This will create the proxy to the WS automatically.
user734577
Well I used "Add Service Reference" by right-clicking the solution on Visual Studio 2010 and I successfully added the web service address to the project. Now my website still runs perfectly so could I say that my application uses the web service and does the calculation on it?
Bruno Costa
Your application has the proxy to connect to the webservice. You still need to call method from webservices to use the webservice. I mean, you need to create the code in the webservice to do the maths and then, call it from client-side or server-side (wtv you prefer).
user734577
Well I have defined methods in the web service (etc. Add, Multiply...) but I have FUNCTIONS in my javascript code so would that still make it work on the web service or what I should do? Sorry I'm asking too much but I'm completely new to this.
|