doubt on calling a webservice from c# script

Hello,

I am trying to call a webservice from a c# script. For what I could understand, I should try with WWW and WWWForm (I also tried using System.Web.Services, the visual sutdio way, but it hans´t worked, as already posted somewhere in the forums).

Then I tried creating a wwwForm and passing it to a WWW object, but I don´t know how to call the intended webservice. I couldn´t succed calling the webservice I wanted.

Below there are some code excerpts showing what I tried creating a wwwForm and www object (but it fails). It gives no error/exception, but it is not working.

//Loading data on wwwform (form).
form.AddField(“xml”, Regex.Replace(doc.OuterXml, “"”, “'”));

//Creating headers for www object (don´t know if it´s necessary).
string[ ] headers = new string[4];
headers[0] = “POST /selectionreceiver/service.asmx/ReceiveXML HTTP/1.1”;
headers[1] = “Host: localhost”;
headers[2] = “Content-Type: application/x-www-form-urlencoded”;
headers[3] = "Content-Length: " + form.data.Length;

//I thought of this to call the webservice. selectionReceiverHost is the address of the webservice (http://localhost/selectionreceiver/service.asmx)
WWW w = new WWW(selectionReceiverHost, form);

//Or this. But neither worked
w.InitWWW(selectionReceiverHost, form.data, headers);

How should I call a webservice? Would someone have an example?

Thanks in advance

Putting another way, my doubt is as follows:

In Visual Studio / C# I can do :

//Instantiating webservice
WS.Service obj = new WS.Service();

//calling a method of the webservice
obj.ReceiveXML(xml);

My question is, how can I do to achieve the same result as the excerpt above within unity?

Thanks

You could try to generate a proxy class with the wsdl utility : start program → visual studio 2008 → Tools → Command prompt and type wsdl to watch the CLI options. It will generate a proxy .cs class that you can instanciate (the same type of class is generated under VS 2008 but hidden for easy of use).

But sincerely I doubt that it would wrk because of the missing of some dlls in the mono framework. Maybe on Windows…?

Otherwise, do a call test with a tool like Fiddler to generate your POST request to your webservice and see what it returns to parse the result (XML…)

The platform makes no difference. Unitys framework are always the same Mono 1.2.5 ones present, independent if windows or mac.

I think webservices work up to a given point (.NET 2.0 at best), but only in standalone distributions.

In webplayer you will have to find an own solution (WWW + a JSON solution + …)

Exact.

And obviously, using the “classic” VS 2008 way won’t never work because the use of the generated events is just impossible…

You’ll have to finally go to POST + XML/JSON…good luck !