Click here to Skip to main content
15,917,481 members
Please Sign up or sign in to vote.
4.00/5 (3 votes)
See more:
I have a aspx page that calls a asmx (webservice). I started with a helloworld example, I added a website to the project put a scriptmanager on the aspx default page and everything worked. I then went on to create many pages in the site and many functions in the webservice. There came a time when I wanted to separate the two, make the WebService stand on its own. That is when all hell broke loose. So to fix it I dropped the web reference to the asmx add created a new one and pointing the scriptmanager to the new webservice asmx file. For some reason I keep getting webservice in undefined error when I try to call it. I went back to step one. I made a new helloworld, uncommented System.Web.Script.Services.ScriptService ran it, tested it and got the path (http://localhost:62579/WS.asmx). I then created a new SEPARATE website with one page with a scriptmanager on it, made the web references and a function to call the webservice

function Test() {
    WS.Service1.HelloWorld(OnComplete, OnTimeOut, OnError);
function OnComplete(data) {
function OnTimeOut(data) {
function OnError(data) {

It fails on the call to the webservice. I know all of the code is correct - It worked before. And yes I checked the config file for the proper paths.

Q1 - Anybody here know what is going on? I searched the web for days & tried every thing.

Q2 - Can a webservice stand on its own? or does it have to be in the App_Code folder of the website that calls it? The only way I have ever got it to work is when they are tied in the same project.

Q3 - Should I even bother with a webservice? Should I be using WCF instead?

Q4 - Are asmx type webservices just another piece worthless RAD crap that microsquat foisted upon us, kinda like that databinding garbage? Only works for the simple stuff? For amateurs only?

Steps to reproduce - create a helloworld webservice and let it stand alone. Create a separate project and then try to call the service.

I gonna kill the next thing that crosses my path
Updated 28-May-11 13:42pm

1 solution

Partial Answer:

Q1: Don't know, but the path to your asmx service is likely to have changed. - Check it is on localhost and check the service's port number: if you are running with Cassini the latter will have changed

Q2: Yes they can stand on their own. They are designed to expose methods across a network, it is even possible to call a service across the Internet, so on the same machine is no problem. You can and should put this into a separate project from the website, and it is preferable to pre-compile the service classes (thus also getting rid of the app-code folder).

Q3: I much prefer WCF, it has greater flexibility a cleaner model and I found Federation easier. That said, the problems your are currently facing with asmx services you will probably face in WCF.

Q4: Absolutely not, although you are writing in .net, you could have written your service in Java. With forethought (about differences between primative types) you can even write a java service and consume it in .net (& vice versa) marshalling objects not only across application boundaries, but frameworks. The basic interaction is:
1) client opens channel to server
2) Client makes request of server (similar to a web browser requesting a page). The request is made using a standard called SOAP
3) The server replies with a SOAP response.

SOAP[^] is an open standard. The "payload" of the message can contain serialized objects if you need them. WCF / Web services are very powerful and they help in enforcing you to tier your code properly so database stuff doesn't bleed through to the UI etc. At my last place of work I designed the customer management system around [WCF - the principle is the same as asmx] web services, and that was for a bank. They also allow you to run multiple front ends through the same back-end code (we had WPF and ASP.NET clients), and they can talk to eachother (look up SOA - Service Oriented Architecture).

The web service paradigm is certainly worth investigating. I'd start with WCF, there are increasing few asmx resources around (it is very old, my first project used them 9 years ago) and in .net-land it has been largely superceded by WCF. You can always expose a asmx style endpoint if you wish, so you won't lose anything by doing this
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900