View Full Version : Calling web service from html
wrath
03-21-2009, 07:05 PM
I have a wcf web service hosted at discountasp. It is working fine in silverlight and from VS, but I would like to run a scheduler to trigger a particular function once a week.
I believe it can be done by calling my service from html using some javascript for help but I havent been able to get any of the examples I looked at working.
Any advice on how to accomplish this?
Can the scheduler call directly into and trigger a service method?
thanks
Joseph Jun
03-21-2009, 10:20 PM
I'm assuming you're referring to the Scheduled Task utility that's in the DiscountASP.NET Control Panel?
If so, the utility will not follow redirects, it just makes a simple HTTP call to a file and if a HTTP 200 response is returned from the web server, it's considered complete.
Since there needs to be some data submitted to invoke a particular method, I don't think there's an easy way around it.
I know it's probably the least advanced solution that you might hear but there was a particular script that I needed to run every ten minutes. I ended up creating a batch file that launched Internet Explorer with a URL appended to it and had it run as a scheduled task in Windows XP.
It worked like a charm as it bypassed a lot of the limitations but I ended up throwing in some JavaScript code to close the browser window as I had forgot that it was running and you could imagine how many windows were open.
wrath
03-23-2009, 09:53 PM
I wanted to use the tool at
https://my.discountasp.net/scheduled-task.aspx
to trigger a web service method by accessing a webpage
I got this expired cache thing working, it wasnt repeating like it was supposed to but I can trigger it to run one time from the scheduled-task
http://www.codeproject.com/KB/aspnet/ASPNETService.aspx
pretty cool work around that guy figured out...
what a coworker showed me which I got working and seems really easy compared to everything else I found from googling.. is this...
start menu -> microsoft visual studio 2008 -> visual studio tools -> visual studio command prompt
then using the command wsdl, do : wsdl /? for info
if you run
wsdl http://www.mysite.com/MyService.svc
it will create a Myservice.cs file which you can then add to an asp web app project, then you can reference the webservice in your project like this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
MyService myService = new MyService();
string message = myService.GetTest();
}
}
}
and trigger it from scheduled-task.aspx by pointing to in this case http://www.mysite.com/Default.aspx
I think you can pass values by putting them in the url
Aristotle
03-24-2009, 05:21 PM
You could also simply add a Service Reference to your asp.net website in Visual Studio 2008.
wrath
03-24-2009, 07:14 PM
I see...
I had done that with my silverlight app, never built asp.net site before which is why I was asking about javascript to trigger my webservice. Wouldnt have minded that info a few days ago, but still I learned a lot in the process.
Thanks for letting me know you can just add web service to asp app. I feel like I knew that, but I dont think any of the dozens of web searches I did returned anything suggesting such. They all had convoluted ways of doing it...
Playemoornala
01-25-2010, 05:29 AM
Hi,
Thanks for your solution. But, these methods wont work for me. I am working in a shared server platform and the package required for creating the perl object through "new Perl" is not installed and not possible for installation also.
I need some htaccess way if possible. Also, I would like to know if there is some method by which PHP will run from HTML pages and also SSI will run to execute perl scripts.
Might be I am asking too much in one go
vBulletin® ©Jelsoft Enterprises Ltd.