I’m working on a game where I need to exchange a lot data between the clints and a database server. I was thinking this was pretty easy using C# and webservices (and a webserver) - and it was, until I tried it in the webplayer. I need to include the System.Web.Services.dll and afaik you cant do that when building for the webplayer (the browser crashes when I try).
So the question is - what do I do?
I could implement my own webservice framework using the WWW class but I’d rather not when the .net one works fine (both client and server side).
I could implement the .net framework in unity using the source code from mono but I have no idea how much work that is - any guesses?
So it would seem that I can use the System.Web.Services.dll in the webplayer. Problem is that when I build for the webplayer atm the browser crashed (both safari and firefox) - it works just fine with the stand alone builds.
I’m gonna have to implement webservices here too, I’m currently learning to use the third party (ingame advertiser)'s service via a basic Windows app, but once I’m done I’ll have to port this into Unity and I don’t know how I’ll do it yet.
Did you make any progress since your post? What DLL are you using, the standard MS.NET System.Web.Services, or the Mono version?
Anyhoo it should be possible to include a workable DLL one way or the other, but I’m afraid the problem will be deeper down: I think the MS implementation of webservices involves sockets, which in turn involves threading, which is out of the scope of classic Unity scripting. In short: if you’re not very careful tidy, Unity won’t clean up for you (as it kindly does for most “game-related” scripts), and you can easily crash the app (instead of just throwing nice managed exceptions that end up quietly in the console).
I once used sockets to query an NTS time server, and as I’m NOT careful tidy, I had such problems and fell back to using WWW… after that everything was a breeze.
So maybe a way to go would be to reuse the highest class available (SoapHttpService perhaps?), modify it so it would use WWW (just for sending and receiving the XML flow, which is basic HTTP after all), then reuse all the XML parsing and SOAP know-how so you don’t have to reinvent the wheel…?
Edit: have you read that post? I’m not exactly sure what zumwalt is trying to do there… looks like he’s implementing a webservice, then the Unity client?
I’m using the mono System.Web.Services.dll and it works fine in the editor, windows and mac standalone. The problem is with the webplayer but it seems that you have use the WWW and I haven’t had time to look in to that.
It seems that we have the same problem - the webservice doesn’t work in the webplayer.
I don’t know the answer to your problem, but I use a lot of web services with just Unity’s WWW class just fine. Using REST, and I just pass XML data back and forth to the web server.
Thanks for the input, could you please elaborate: what do you mean exactly by “using REST”? what implementation?
The matter here isn’t to know if it’s possible or not to do webservices in Unity, because we all agree that it all boils down to http which the WWW class handles ok, but rather of finding the best practice.
So we’re wondering if it’s possible to use System.Web.Services, built into the .NET framework.
Personally I’ve used it for years on web applications so I know it in and out, plus it’s integrated into Visual Studio: I can just throw the WSDL at it and it generates sync async RPC stubs, events, etc… peachy 8) !
I ended up using WWW, yes.
Basically you have to query serviceUrl/functionName then add post arguments for each function argument, then parse the results…
There are different protocols, different services, so syntax may vary. I can’t give you my code samples as they are proprietary but I remember I did a test project where I queried a couple public services, I could dig it up if you want.
I only had a few functions to query so I did it all manually but one could make a wrapper fairly quickly… error handling is a bitch though.
Oh, I forgot: I used WWW because I needed a webplayer, but standard .NET-generated webservice clients actually work in standalones.
That was back in 2.0, I wouldn’t be surprised if they now worked in 2.1 because I think UT raised a few limitations… never checked though.
We’re using WCF Webservices and ended up writing our own wrapper business DLL to serialize requests to and from the client under Unitiys WWW class. It’s a bit of work, but it’s running nicely - still hanging out for .Net3 in Unity.