Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity and Web Services

Discussion in 'Multiplayer' started by DroxXodia, Sep 29, 2011.

  1. DroxXodia

    DroxXodia

    Joined:
    Sep 29, 2011
    Posts:
    3
    Hi folks,

    I'm thinking about using Unity for a game project in the near future. My project would be heavy on the historical data and I will be using some sort of DB such as sql server or mysql.

    I plan on downloading Unity soon and checking it out for myself. But I was hoping that some of you here would kindly share some insight as to how it may work.

    Typically when I write database content integrated into an application of whatever sorts I write a .NET WCF Web Service. Or If I can not use .NET and need to use C++ I will use Apache Axis or even just write pure http requests in C++. I never directly use DB interfaces unless it's my only choice as that is highly coupled and I don't like to be stuck like that.

    So what I'm really wondering is if you guys having done similar stuff in Unity use the built in WWW and WWWForm classes, or do you use the .NET WCF etc...

    For instance lets say I have some web services hosted on my server somewhere, and it adds 2 numbers and returns the result. Can I use the WWW and WWWForm objects, or should I stick with WCF?

    I haven't had the time to dig in yet to the Unity documentation, so I'm not even sure if WCF is supported.

    Any insight would be greatly appreciated, and I look forward to being a part of this Unity Community!
     
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    WCF is not supported on Mono afaik, at least not 2.6.x which unity runs on. Also, why are you making it so hard for yourself? You don't like that the DB is coupled straight with the application so you use some weird WCF/HTTP layer between, have you actually changed the DB on an app that is deployed?
     
  3. DroxXodia

    DroxXodia

    Joined:
    Sep 29, 2011
    Posts:
    3
    Yep I was just reading up on Mono and pretty much came to the same conclusion that WCF is not supported yet, which is a bummer as WCF is such a powerful aspect of .NET.

    It's not really making it hard on myself so much as preparing for the future. I like to have db details separate from an application for a lot of reasons. Not that I haven't made a lot of apps with direct sql in them, but I find it beneficial to not do so.

    One reason, would be that I don't want to have to redeploy something when a query changes. I may have a query that's fast now, but in a year it may need to be rewritten using OLAP, or something else that speeds up the process. I don't want my application to have to know about that. I want the application to use a resource hidden behind an interface. Transparency is something I found to help the longevity and maintainability of my applications.
     
  4. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    I agree Drox, that's a pretty basic approach in any application I've worked on in the last 5-8 years (before that raw JDBC hell or worse). I'm using a DTO layer right now to decouple the data layer from my server code. It's not perfect but you can at least stub out the data layer and write a particular driver to handle things using whatever (NHibernate) for now until support does come or an alternative avails itself.

    One thing I've noticed about game development is that it seems to lag a few years to enterprise software development in terms of both tools and techniques - but some of that may be a bit misleading as games tend to have very short development lifecycles, so perhaps building for longetivity/maintainability is not as important as some of the "dayjob" code i've written.

    Theres some kind of WCF "pulse" over here: http://veritas-vos-liberabit.com/monogatari/2010/09/current-wcf-40-status-in-mono.html

    Anyhow, let us know what approach you end up taking, i'll be interested to hear what path you take.
     
  5. DroxXodia

    DroxXodia

    Joined:
    Sep 29, 2011
    Posts:
    3
    Yep that is not a bad idea Lypheus. I may consider that.

    I may also think about creating an HTTP wrapper for simple XML either restful or soap, or just plain xml, basically make a lightweight WebService client out of sockets or those WWW classes.

    I will need to digg into Unity more though before I have any idea what my path will be. Looking at maybe a few weeks from now I may have a plan.

    I do agree though about the lag of enterprise technologies in game development. I think the main reason is because games are so hard to finish that most of the engineering people focus on game related tech and not stuff that will improve meta game. But I do think it's getting better over time. I recently read an article about the Gears of War team and how they datamined their engine for users to see meta data on websites etc... Was an interesting read and they actually used some solid enterprise technology.
     
  6. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    You can use WCF just fine, but only in standalone builds. I wrote a blog post about it here http://randomrnd.com/2011/08/21/webservices-in-unity/

    I was also going to write a blog post about using Apache Thrift, but I haven't gotten that far yet. I did put a tidbit at the wiki, http://www.unifycommunity.com/wiki/index.php?title=Using_Apache_Thrift_Webservices_From_Unity for using Thrift via the WWW class, but it should be re-written to use a co-routine. With this you can use Thrift services from the webplayer, or you can consume the services via a socket.

    You can read more about Thrift at http://thrift.apache.org/
     
  7. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Very nicely written article - thanks for the efforts steego!
     
  8. AlexZ

    AlexZ

    Joined:
    Sep 17, 2009
    Posts:
    263
    Thank you very much for the blog. I am using this to consume with asmx. It seems it doesn't work in the web player, with no error (I also had to copy over about 10 extra dlls to even get it to build as a web player). Any ideas about how to get this working in the web player?

    My only thought is to do a web player platform check in the service script generated to wsdl to do an external call to a js if it detects its running in web.

     
  9. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,814
    WCF runs fine using Mono and Unity.

    You need to include..
    * System.Runtime.Serialization.dll
    * System.ServiceModel.dll

    There is an example of using WCF here..
    http://wiki.unity3d.com/index.php?title=Webservices_In_Unity
     
  10. AlexZ

    AlexZ

    Joined:
    Sep 17, 2009
    Posts:
    263