473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Calling a web service via javascript

115 100+
I've searched numerous places on the web and haven't been able to get my solution to work. I have set up an web service and all works perfectly. It a very simple one just one method that retruns hello world as a string

Expand|Select|Wrap|Line Numbers
  1. namespace MyWebApp
  2. {
  3.     /// <summary>
  4.     /// Summary description for FirstSharePointWebService
  5.     /// </summary>
  6.     [WebService(Namespace = "MyWebApp", Name = "FirstSharePointWebService")]
  7.     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  8.     [System.ComponentModel.ToolboxItem(false)]
  9.     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  10.     // [System.Web.Script.Services.ScriptService]
  11.     [System.Web.Script.Services.ScriptService]
  12.     public class FirstSharePointWebService : System.Web.Services.WebService
  13.     {
  14.         [ScriptMethod]
  15.         [WebMethod]
  16.         public string HelloWorld()
  17.         {
  18.             return "Hello World";
  19.         }
  20.     }
  21.  
I have then created a web part in SharePoint. In this web part all i am doing is adding a literal control to the page which is an input button. I am also adding another literal control which places the javascript on the page.

Expand|Select|Wrap|Line Numbers
  1. this.Controls.Add(new LiteralControl("
  2. <script language='javascript' type='text/javascript'>(function(){
  3. alert(1);
  4. service.useService('http://localhost:22222/12/TEMPLATE/LAYOUTS/AJAX/FirstSharePointWebService.asmx?WSDL','FirstSharePointWebService');
  5. }());
  6. function callService() {alert(2);
  7. MyWebApp.FirstSharePointWebService.HelloWorld(callComplete, callError);
  8. function callComplete(result){alert(result);}
  9. function callError(result){alert('ERROR');}
  10. </script>"));
  11.  
  12. this.Controls.Add(new LiteralControl("
  13. <input type='button' id='pow' value='Get Name' onclick='callService();' />"));
  14.  
  15.  
When i click on the button i get the callError() output which indicates it's all hooked up happily enough but something is wrong in the callComplete method and i can't spot what!

I am guessing it can't find the MyWebApp.FirstSharePointWebService but i'm not sure.

Any pointers tips trick would be massively appreciated. Cheers
Truez
Mar 6 '12 #1
0 1375

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: elsenraat_76 | last post by:
Hello! I was wondering if someone could help me out with a problem I'm having? I'm trying to input a javascript value into an anchor tag (from a function), but don't have an event to call the...
3
by: MicroMoth | last post by:
Hi, I'm trying to call a Javascript function within a foreach loop. I am loop over a series of users and I want to call the JS function which opens a new window, passing in the user id to each...
13
by: monomaniac21 | last post by:
hi i want to be able to trigger a javascript style popup alert in php (i want a message displayed on the actual page) is this possible?
5
by: Newbie Coder | last post by:
Hello all I have 3 functions in a javacrip file (MyScript.js), which is added to an ASP.NET 2.0 project 1) no right-click 2) no select text (copy...) 3) History.Back()' How do I call...
6
by: Ajit Goel | last post by:
Hi; We have a Javascript function which I have been tasked to move to a CSharp class. This javascript function uses Regular expression extensively. This function has a string input parameter and...
1
by: susmitha | last post by:
hai iam a fresher in .net.My problem is I have one javascript sourcefile and some javascript functions in my aspx page like shown below. <script language=javascript...
2
by: moni | last post by:
Hi, I wanted to call a javascript function function showAddress(address) { ..... } from the aspx.cs file from the Gridview_RowCommand function
15
by: Sampat | last post by:
Hi, I wanted to know the performance of calling a function pointer v/s a normal function call in javascript in a scenario where there are multiple calls in the js to the same function. Please...
1
ganesanji
by: ganesanji | last post by:
Hi all, I have written a cpp prgram and a javascript function for start,stop timer. I want to integrate the timer javascript function from my cpp program. I don't know how to do it. Anybody...
3
by: ravitunk | last post by:
hi..i have a javascript function which uses window.open() function to open another window... as below... <script language ="JavaScript"> function openWin(url) { ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.