.exe (Standalone) builds & executes on development PC, but no where else (consumes a .net SOAP web service)

Hi, I'm working to an insane deadline (two days from posting this message!) and posting to this forum for inspiration. It's my first post to these forums so apologies if its directed to the wrong place.

I've built a PC standalone self executable in Unity3 that consumes a .net SOAP webservice. Everything builds fine in the Unity editor and the standalone executable file runs fine on Windows 7 (SP1). The application communicates correctly with the webservice (this web service just takes a string input and returns a random string in response).

The problem is when I try the .exe on another PC. The application crashes when trying to communicate with the .net service. I've tried enabling 'script debugging' and looked at the output trace. The standalone .exe gets as far as communicating then crashes - with no helpful error messages - it just stops logging. If I move the .exe back to the PC that it was developed on, all is fine!?!

I've looked over the forums and checked I've performed the following:

  • The application is NOT being used as a webplayer (.unity3D) - so the web-player sandbox isn't the cause.

  • I've built the wsdl stub class using the Visual Studio command line prompt: `wsdl -out:VPDentistv01.cs /protocol:SOAP12 http://www.myserver.com/mywebservice.asmx` (I've also used /protocol:SOAP)

  • I've tried communicating with the stub/web service by wraping it into another .net class, that is compiled as a dll (.net 2.0). The dll is placed in the Plugin folder and is present in the Plugin folder of the build.

  • I'm building with the full .net library, not the subset.

  • The test PC I have is also running Win7 SP1 operating system with .net 3.5 framework. I've disabled firewall and anti-virus (yes I'm that desperate!) to check its not blocking communication with the web-service.

I'm out of ideas. I am new to Unity (5 days experience so far) so I've likely missed somethig basic. What I can't understand is why the .exe works on the PC I develop with but not on another PC running the same environment.

I'm aware that its best to post my code as an example, but to be honest I don't think the code is faulty - as its builds and executes as a self executable ok on my dev pc. It seems its a build setting or security / sandbox setting I'm missing.

PS: Not sure if this is significant, but I develop on a MacBook Pro using boot camp. I have Unity installed on the Windows 7 partition of the MacBook where the .exe works fine. However on the Mac partition, a the .app fails (on the same machine).

Any help, or ideas - much appreciated!

Thanks for all those who viewed this question. I didn't find a solution but I did find a work-around. I thought I'd post it here in case anyone else had the same problem.

As my web-service was only receiving and returning a string, I was able to configure the .net web service to accept GET requests in the web.config file to cover all methods in the service:

<webServices>
    <protocols>
        <add name="HttpGet"/>
    </protocols>
</webServices>

Alternatively, you can use the following attribute if you wish to limit GET requests to one particular method:

[ScriptMethod(UseHttpGet = true)]
public string HelloWorld()
{
    return "Hello World";
}

Instead of use wsdl to generate a stub, I used the WWW class that sent the url as a string. The string was concatenated to format the GET request for a webservice. The method I used in a Unity c# class is below:

public IEnumerator getMyWebService(string _inputText)    
{    
       string url = "http://www.myserver.com/mywebservice.asmx/myMethod?inputText=" + WWW.EscapeURL(_inputText); 
       WWW www = new WWW(url); 
       yield return www;
       Debug.Log(www.text); //Do something with the response as the www object.    
}

Finally the line of code below was inserted into an Awake(), Start(), Update() or onGUI() method, to invoke the web service as-and-when required:

StartCoroutine(getMyWebService(inputText));

I would have liked to get a solution that used SOAP so I could efficiently handle the retured object from the web service. Hoever the deadline I had meant I had to find a workaround quickly!

This workaround had the added advantage of allowing the Unity project to be compiled as a Web Application (.unity3d) - which is prevented in Unity3 if you use a wsdl stub class / SOAP approach. So some benefits I guess :-)

(If you publish your .unity3d file on the same server as your web-service, then there is no need for a cross domain xml file at the root of the server)

If there is anyone out there ever in the same situation as me, I hope this is of use!


EDIT : Additional Info by Meltdown

To add to Luke’s excellent answer, many people may be wondering how to get rid of the XML that is returned with the WWW.text response from the server.

The following method accomplishes this…
Courtesy of [this post][1] from Snipplr.com

string StripXML(string source)
    {
        source = source.Replace("

", “”);
char buffer = new char[source.Length];
int bufferIndex = 0;
bool inside = false;

        for (int i = 0; i < source.Length; i++)
        {
            char let = source*;*

if (let == ‘<’)
{
inside = true;
continue;
}
if (let == ‘>’)
{
inside = false;
continue;
}
if (!inside)
{
buffer[bufferIndex] = let;
bufferIndex++;
}
}
return new string(buffer, 0, bufferIndex);
}
[1]: http://snipplr.com/view.php?codeview&id=20590