BlackBerry and .NET WebService Tutorial (It Works!) - Part 3 PDF Print
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 

 
0 #3 RoshanThecho 2010-03-19 07:21
How can I pass complex type to the server from the client side if I have a WebMethod that accept the object of Complex type? Suppose I have a webmethod like this
[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?
Quote
 
 
0 #2 TienDX 2010-02-23 19:15
Hey,i read your code,but i'm a beginning learn about websevice and programming BlackBerry..i need some help to detail How to do access websevice from Blackberry..so,with your sample i understand a bit of problem.i need more,can you help me,please.
thank your help.
Quote
 
 
0 #1 Tommy 2010-02-01 05:59
We seem to have font tags all over the shot boss.

May need to revisit this post =)
Quote
 

Add comment


Security code
Refresh

Sponsored Links