19

I'm currently implementing a Silverlight application using WCF for the communication between client and server. I've heard that using WCF we're bound to use some Microsoft technology at the client side, and can't easily replace this with "anything" - at least with the default SOAP implementation of WPF.

So my questions are:

  • Is this true?
  • What about Restful WCF services? I picture a plain REST implementation, and any client could communicate with this server side through REST. Yes? No?
  • What are the (good) alternatives to throwing out WCF? And why would I want to do that?
stiank81
  • 25,418
  • 43
  • 131
  • 202

5 Answers5

14

I'm apart of the core team that maintains ServiceStack - a mature Open Source alternative to WCF: modern, code-first, model-driven, WCF replacement web services framework encouraging code and remote best-practices for creating terse, DRY, high-perfomance, scalable REST web services.

It has automatic support JSON, JSONP, CORS headers as well as form-urlencoded/multipart-formdata. The Online Demos are a good start to look at since they all use Ajax.

In addition, there's no XML config, or code-gen and your 'write-once' C# web service provides all JSON, XML, SOAP, JSV, CSV, HTML endpoints enabled out-of-the-box, automatically with hooks to plug in your own Content Types if needed.

It also includes generic sync/async service clients providing a fast, typed, client/server communication gateway end-to-end.

This is the complete example of all the code needed to create a simple web service, that is automatically without any config, registered and made available on all the web data formats on pre-defined and custom REST-ful routes:

public class Hello : IReturn<HelloResponse> 
{
    public string Name { get; set; }
}

public class HelloResponse 
{
    public string Result { get; set; }
}

public class HelloService : Service 
{
    public object Get(Hello request)
    {
        return new HelloResponse { Result = "Hello, " + request.Name };
    }
}

Above service can be called (without any build-steps/code-gen) in C# with the line below:

HelloResponse response = client.Get(new Hello { Name = "World!" });
response.Result.Print(); // => Hello, World

And in jQuery with:

$.getJSON('hello/World!', function(r){ 
    alert(r.Result); 
});
Community
  • 1
  • 1
mythz
  • 141,670
  • 29
  • 246
  • 390
  • 7
    You have mentioned this as 'Open Source'. This looks like a commercial product (even though you give a 'lite' version for free.) Is the source code available in Github? – James Poulose Nov 16 '14 at 05:08
  • This is "Openware", the code itself is open source, but it is hard to use without paying for the "Pro version". The tutorial, for example, requires the installation of a paid Visual Studio extension. – Daniel Santos Sep 19 '16 at 19:29
  • @Daniel The [ServiceStackVS](https://github.com/ServiceStack/ServiceStackVS) VS.NET Extension is free to use, it installs the latest version of ServiceStack v4 which is free to use within the [free quotas](https://servicestack.net/download#free-quotas). All docs for the BSD/free v3 of ServiceStack is available at: https://github.com/servicestackv3/servicestackv3/wiki – mythz Sep 19 '16 at 20:10
  • 1
    @mythz So v4 is not open source. Perhaps you should modify this answer. – Daniel Santos Sep 19 '16 at 20:37
  • @Daniel v4 is dual licensed under an OSS [AGPL/FOSS Exception](https://github.com/ServiceStack/ServiceStack/blob/master/license.txt) as well as a Commercial License suitable for use in closed-source / commercial projects. – mythz Sep 19 '16 at 20:44
  • Warning: technically "open source" but definitely *not free* – Kempeth May 07 '19 at 07:23
12

I've heard that using WCF we're bound to use some Microsoft technology at the client side

Well, then you've been lied to!

Many vendors and open source libraries support SOAP - it's a W3C standard, not a Microsoft-specific idea.

One great alternative for a RESTful service is ASP.NET MVC, which I've found a very easy way to expose methods directly as URLs.

Daniel Earwicker
  • 114,894
  • 38
  • 205
  • 284
  • Oh, well - that's a good thing then. I know SOAP isn't MS-specific, so I didn't really understand why WCF with SOAP would bind us to Microsoft. Thx for clearing this up! And SOAP is used by default when creating a WCF service, right? – stiank81 Aug 11 '09 at 19:46
  • From the name "ASP .NET MVC" sounds like something you typically use in - well - an ASP .NET application. Sure - my Silverlight is wrapped in ASP, but will it suite my Silverlight app just as fine as it would for an ASP app? – stiank81 Aug 11 '09 at 19:48
  • No, and yes ;). You have to specify binding(s) explicitly. So - you have to choose, therefore, word "default" doesn't fit here, on the other hand, you don't have to turn any magic option somewhere, it's your choice. – Marcin Deptuła Aug 11 '09 at 19:48
  • 1
    @bambushka - The Silverlight part of your app runs at the client. Are you trying to think of a way to allow clients elsewhere connect directly to that app? I'd assume not (it's basically not going to work, anyway.) Any kind of contactable web service must be running at the server. So by definition we're not talking about anything directly to do with Silverlight. We're talking about the server side. And that's where you'd use ASP.NET MVC. It's just a very easy way to cook up a custom server that can return data over HTTP; you just write a method or two, and make them return JSON or whatever. – Daniel Earwicker Aug 11 '09 at 19:54
  • No - nothing will connect to the Silverlight client. Yes - it is the server side that is of interest in this question. Oh - I see. But you don't have any ASP on the server side - isn't the name a bit confusing? Will look into ASP .NET MVC. Thx! – stiank81 Aug 11 '09 at 20:22
  • ASP stands for Active Server Pages - seems pretty clear to me :) Are you really using *classic* ASP? i.e. not ASP.NET? – Daniel Earwicker Aug 11 '09 at 20:56
  • Oh, thx for clearing that up - have never worked with ASP.. Are anyone still using classic ASP? I meant ASP .NET.. – stiank81 Aug 13 '09 at 10:06
  • If you use wshttpbinding then isnt that microsoft specific? – user1438082 Dec 02 '13 at 22:53
4

WCF is SOAP-based (by default - also support REST) and can easily interoperate with any client that can understand and speak SOAP.

Those include languages and systems like Java, PHP and many many more.

WCF is Microsoft's implementation - but the standards are all international and interoperable standards. Nothing about the standards is Mircosoft specific.

Marc

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 2
    Everyone's saying WCF doesn't bind me to Microsoft :-) Good to hear - obviously I've been falsely informed.. Thx! – stiank81 Aug 11 '09 at 19:56
  • 4
    While it sounds very good "on paper" in reality there is still plenty of small but annoying problems with interopibility... – Ray Aug 11 '09 at 20:45
  • Please elaborate on the "small but annoying problems with interoperability". Otherwise, you're as bad as the people who told the OP that WCF would bind him to Microsoft. – John Saunders Aug 11 '09 at 23:01
3

WCF gives you a level of abstraction over the way you are/want to communicate. So, you can choose binding that is Microsoft-specific, but you can also use SOAP protocol, or, you use both, so non-Microsoft client will be able to communicate through fe. SOAP, and other client can use more robust ways.
As for REST you might want to look at Hanselman's talk on NDC here. It might not answer you question directly, but it might point you something.
As for alternatives, I don't see anything that would run on .NET, besides web services (but, because WCF gives you all this and much more, I would rather consider it as an older way, than real an alternative).

Marcin Deptuła
  • 11,789
  • 2
  • 33
  • 41
  • Thx! Will check out Hanselman's talk (proper link: http://media01.smartcom.no/microsite/asx.aspx?eventid=4499). Well - if WCF doesn't bind me to Microsoft I'm happy with it. I will consider changing to REST though.. I feel that's often preferred over SOAP these days - but I might be wrong? – stiank81 Aug 11 '09 at 19:53
  • 1
    REST is more fashionable at the moment. SOAP is overkill for most applications. XML is a poor fit for representing hierarchical data anyway. SOAP/WSDL is a giant mess of a standard, incorporating the XML Schema standard (which incorporates a regular expression standard from the Unicode consortium). Compared to all that, REST is almost nothing, basically just HTTP. And yet is more capable than basic SOAP (e.g. you can return an image as a binary stream). – Daniel Earwicker Aug 11 '09 at 20:00
  • 1
    I don't feel strong enough in this field to answer this question, but I know one thing, that Hanselman mentioned there - those technologies are great for client apps etc., but sometimes, the whole idea of getting (often) binary data and putting them as text inside brackets can be a too much of overhead. In WCF I like the fact, that I can write logic once (implementations of contracts) and then access them using many ways with ease. – Marcin Deptuła Aug 11 '09 at 20:00
  • @Ravadre - have you got a link to that Hanselman comment? The point I was making was that HTTP itself can return binary without needing to encode it as text, so if you (for example) want to return a PDF or JPEG or a ZIP download as the result of the method, you can just do that, by returning a ContentResult or a FileResult, etc. Take a look at the classes derived from http://msdn.microsoft.com/en-us/library/system.web.mvc.actionresult.aspx - so if you just want to return a stream of stuff as the result, it is zero coding effort and optimally implemented. – Daniel Earwicker Aug 12 '09 at 18:38
  • @Earwicker - You are right, this 'comment' is actually an answer at the end of the video, the whole point of my comment was (and I think - also Hanselman's), that using those formats like JSON generates overhead, so it's not always the best way to use them (ie. when returning huge amount of data). My last comment may be not precise (mostly, because it had to be short ;) ) - I'm not neglecting possibilities, I'm just pointing out, that using "text" protocols (soap,json) to return data is easy and convenient (fe. for easy parsing with js), but not always the best way to achieve the goal. – Marcin Deptuła Aug 12 '09 at 19:06
1

For java - wcf interopibility check Sun's Project Tango link

Ray
  • 1,585
  • 9
  • 10