|
BlackBerry and .NET WebService Tutorial (It Works!) - Part 3 |
|
|
|
Wednesday, 27 January 2010 02:28 |
|
Sorry for not keeping this up to date, but I haven't had much time to revisit this since my original post. Fortunately, Michael Soltys was able to figure it out and he was kind enough to share. So without further delay here is what Michael sent me: .NET web service
[WebService(Namespace = "urn:tempuri")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class HelloWorldService : System.Web.Services.WebService
{
[SoapRpcMethod(), WebMethod]
public Complex HelloServer2(string user, string pwd)
{
Complex myObj = new Complex();
myObj.name = string.Format("user:{0}, pwd:{1}", user, pwd);
myObj.value = 42;
return myObj;
}
public class Complex
{
public string name;
public int value;
}
}
In HelloWorld.java:
String serviceUrl = "http://localhost/HPServices/HelloWorldService.asmx";
String serviceNamespace ="urn:tempuri"; //saw a post saying "http://tempuri.org/" might cause a problem. Who knows?!
String soapAction = "urn:tempuri/HelloServer2";
SoapObject rpc = new SoapObject(serviceNamespace, "HelloServer2");
rpc.addProperty("user", "testuser");
rpc.addProperty("pwd", "123password");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.encodingStyle = SoapSerializationEnvelope.ENC;
envelope.bodyOut = rpc;
//envelope.dotNet = true;
// Add the mapping so that the return value can be converted back to our Complex object.
envelope.addMapping("urn:tempuri/encodedTypes", "Complex", new Complex().getClass());
Did you see that?!?!?!
//envelope.dotNet = true; Nice. Thanks Michael.
|
Comments
[SoapRpcMethod( ),WebMethod]
public Complex HelloServer(Com plex obj)
{
Complex myObj = new Complex();
myObj.name = obj.name + " World";
myObj.value = obj.value + 100;
return myObj;
}
SoapObject rpc = new SoapObject(serv iceNamespace,"HelloServer");
Complex com = new Complex();
com.name="Hello";
com.value=50;
rpc.addProperty(Com plex, com); //How to pass complex type as we pass other simple type?
other code.........
envelope.addMapping("http://tempuri.org/encodedTypes","Complex", new Complex().getClass());
other code.......
Complex myObj = (Complex) envelope.getResponse();
add(new RichTextField("Name: "+ myObj.name + "\n" + "Value: " + myObj.value));
I am trying to get output as:
Name: Hello World
Value: 150
Please help me?
thank your help.
May need to revisit this post =)