-1

I'm very new to WCF and I'm trying to wrap my head around how it works. Please keep in mind that I am (by no means) a web developer and I have no intention to use it that way. However, it seems to be the way to go for my application. All of the articles and tutorials I've seen online, including the de-facto standard "Best Practices" article, all seem to assume that it is being used with a database and a web service and so it's kind of difficult to wrap my head around what they're trying to convey.

Basically, I have a project with some classes that will evolve rapidly over time (so I'm assuming agile versioning would be best). I'd like old versions of that class to be backwards compatible with newer versions and hopefully vice-versa. Now, as far as I'm currently concerned, I'll only be using these classes to store data; I don't really need any methods aside from getter/setters. That's why I say that I don't really need a service contract, or so I believe. The objects will basically be used as singletons to pass around access to this global data set. I want to be able to share these data objects among multiple applications on multiple machines as well.

Is there any way I can do this with WCF and how would I go about it. I'd appreciate any explanation of the framework that keeps the web and database stuff to a minimum. And of course I'm open to other suggestions that achieve what I want as well. Thanks

audiFanatic
  • 2,296
  • 8
  • 40
  • 56

2 Answers2

2

Ok, then I thoroughly recommend downloading the ServiceStack NuGet package and using the ServiceStack.Text.TypeSerializer - the API looks like this (dead easy)

string serialString = ServiceStack.Text.TypeSerializer.SerializeToString<TObject>(content);

You get your JSON string version of your class, then you can use the reverse

TObject assetValue = ServiceStack.Text.TypeSerializer.DeserializeFromString<TObject>(serialString);

To get it back again. In the middle you can save it, send it, or whatever. Its very forgiving of change to structure.

PhillipH
  • 6,182
  • 1
  • 15
  • 25
1

In my experience WCF is very heavyweight for what you are trying to achieve. If you have simple "data transfer objects" then you would possibly be better simply creating a REST service (or other web service that returns JSON). You seem to want to serialize data backwards and forwards between several machines - WCF could do that for you - but you'd probably be better off with a simple store metaphor, which REST does very well and is much simpler to implement in the MVC framework.

PhillipH
  • 6,182
  • 1
  • 15
  • 25
  • Yeah, I agree; it did seem very heavyweight. Are there any good resources on REST; particularly one that's not too web/database based? – audiFanatic Jan 07 '15 at 14:27
  • Well, REST is really just an HTTP calling syntax that returns JSON (typically) serialized classes. Given that, there are no "non web" REST implementations. Your API is going to be hosted on IIS and talking HTTP so you could do worse than follow http://www.asp.net/web-api/overview/older-versions/build-restful-apis-with-aspnet-web-api – PhillipH Jan 07 '15 at 14:45
  • Sorry, but that's still all Greek to me. I'm familiar with JSON and XML as a means to store data, but again, I've never used them in a web-based application, so I'm still not quite getting it. – audiFanatic Jan 07 '15 at 14:49
  • Ok, just consider that JSON is a more compact, and slightly less rigid way of passing data. Its just a format for returning data from an HTTP call - however the .net framework has multiple serializers (binary, Json, XML, DataContractSerializer). I think you need to be more specific about how you want to pass data between your applications - from your responses maybe this is going to be via a disk file rather than HTTP call ? Json just happens to be more resilient at handling Class/Data mismatches, – PhillipH Jan 07 '15 at 18:27
  • Yes, I do understand JSON; it's the HTTP call that confuses me. As far as I'm concerned all of this will be done locally, hence the confusion. – audiFanatic Jan 07 '15 at 19:42
  • ... see my subsequent answer. – PhillipH Jan 07 '15 at 22:23