0

Alright, I almost reached a point of frustrations that I want to go to break things. Figurly speaking of course.

For about week now I try to learn to make a web service written in C# (WCF, ASMX web service, I don't care, whatever is best) and I want to reach the web service with JQuery/AJAX (and no ASP.NET webforms cause I want to use AngularJS) or if it is better, generate a proxy that calls the WCF.

What I have tried so far: I started with the normal web service (In Visual Studio 2012: start an empty ASP.NET Web application and add an web service to it). I run the webservice and it works. Then I publish the web service to IIS so I can reach it from a different computer. And then the first problem shows up, it wont work. Seems I had to install ASP.NET at IIS. And it works but when I call the web service on the different computer I get the message that I can only invoke the web methods on the local machine.

Looking on this message gives me a lot of the same results: I have to configure my web.config and I have to add httpGet and httpPost tags to it. So I do that, but... still doesnt work. Searching further doesnt give me the right answer or solution.

But what I did read is that this way of web service is out of date and I should use WCF. Since I want this to work, and it doesnt matter in what way, as long as the service is in c# and client is JS (with AngularJS) I am happy.

So I searched for tutorials, found a lot of them, followed many of them but none of them worked, at least, not for me. Errors and messages is what I get, and when I solve one message or error, I get the next one.

With WCF I am now that far I could call the operation contract but I couldnt pass the parameter of the operation contract. Maybe Json Syntax error? I don't know. According to some anwers on StackOverflow I had to add a RequestFormat. So I did. And I also had to change the WebGet to WebInvoke. But now I get a 405 error and searching on it, it seems a Post/Get issue. So I change the Type in the AJAX call to Post (which it should be according to the service headers), but the call stays on GET. And that I simply don't understand and after a long time of trying it starts to frustrate me.

The bottom line is: What is the best practice when it comes to web services? Is there a good written tutorial which handles every point so it actually does work in the end? Or what and I doing wrong? Cause, since there are probably thousands of web services on the internet, it is surely is something I am doing wrong, but I can never figure out clearly what.

Cornelis
  • 1,729
  • 5
  • 23
  • 39

1 Answers1

1

Ensure WebDAV is not running on the site/server that's hosting your web service, in web.config:

<system.webServer>
    <modules>
        <remove name="WebDAVModule" />
    </modules>
</system.webServer>

I'd also recommend checking out ServiceStack for .NET web services, lot's of documentation & samples, e.g. HelloWorld & Wiki

Gavin Faux
  • 481
  • 2
  • 8
  • Thank you for the links. I am gonna look into it and see if I get it to work. – Cornelis Jun 02 '13 at 20:25
  • Before I started to look at the link, I tried out the option to turn off the WebDAV first. And that worked. Now I got one webservice to work, I was wondering, is the SerivceStack much better then asmx webservices? cause if so, I am gonna try that as well. – Cornelis Jun 03 '13 at 18:50
  • That's a matter of opinion and depends on what your building, for a one off simple web service (e.g. give me a list of countries) using ASMX may well be "good enough", however ASMX is now a legacy technology, replaced by WCF, and to a degree WebAPI (supplements WCF rather than replaces it). See [this post](http://stackoverflow.com/questions/9699083/servicestack-vs-asp-net-web-api/9709236#9709236) for an overview of the differences. Also [Razor Rockstars](http://razor.servicestack.net/) has examples of using ServiceStack with AngularJS..... – Gavin Faux Jun 03 '13 at 19:45