Link to home
Start Free TrialLog in
Avatar of d34thd34l34r
d34thd34l34r

asked on

iPhone how do i retrieve a .net dataset from a webservice

Hello,
          I am trying to pull a dataset from an existing webservice but have no clue how or if it can be done in cocoa touch.  I can consume the .net webservices just fine however, when trying to interact with a .net based object type there are obviously some complications.  Any advice would be GREATLY appreciated as i am just breaking the ice in the beautiful world of mac development.

Avatar of Alexandre Simões
Alexandre Simões
Flag of Switzerland image

So is the .net web service return a DataSet or DataTable object?

What is the method signature (WSDL)?
Avatar of d34thd34l34r
d34thd34l34r

ASKER

Yes
"Yes" is a pretty good and explaining answer to witch I can just say "Thanks!"
I am sorry for being short...  I though i was typing in another posting... I do apologize for being disrespectful.   I will post the WSDL when im not on a phone and i can get to a machine.

Method signature basically looks like so:

 DataSet ( string username, string password ){

}

it is WSDL... i have read that many examples in which REST web services are used however if possible i would like to keep the SOAP based.
Since you havn't given complete examples I will create an example.

I created a simple web method (simalar to your sample) :
    [WebMethod]
    public DataSet HelloWorld(string username, string password )
    {
        DataSet data=new DataSet();
        data.ReadXml(new StringReader(@"FredTester"));
        data.AcceptChanges();
        return data;
    }



What the reported WSDL looks like the attached HelloWorld.WSDL.txt.  When you call the web service, the results are a string that matches the DataSet XML (see attachement WSResults.txt
 
WSResults.txt
HelloWorld.WSDL.txt
Would it be easier if i just used the .net xml serializer and serialized the data so objective c could pick it up a little easier.  Obviously this would expose the values being passed back to the iphone but, as with any language you could write some AES encryption methods relatively easily that could take care of that exposure... What do you think?
Once you register your Web service using the  /usr/bin/WSMakeStubs command, the stubs will show how it registered the Return type.  It will either be a NSDocument object or a NSString object.
MogalManic, guess we were posting at the same time...  Thats interesting... Im going to look into that a little further as it seems, by your example, i should be able to consume it relatively easily!  Im going to try that today and get back to you... Thanks...
ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Followed you instructions and am tracking so far however, do you know of any reason why the WSMakeStubs would create files with errors in them... Normally if this wasnt such a new language to me i would be able to figure it out however, im still a noob @ objective c... See the attached file and i will also attach the code for your review.... Thank you...
/*-
 * WSDL stubs for:  http://localhost/bla/HHU_Authorization.asmx?wsdl
 *   Generated by:  d34thd34l3r
 *           Date:  Wed Jul 22 18:58:20 2009
 *        Emitter:  Objective-C
 */
 
#ifndef __HHU_Authorization__
#define __HHU_Authorization__
 
#import <CoreServices/CoreServices.h>
#import <Foundation/Foundation.h>
#import "WSGeneratedObj.h"
 
/*-
 *   Web Service:  HHU_Authorization
 * Documentation:  <not documented>
 */
/*-
 *   Method Name:  Authorize_Device
 * Documentation:  <no documentation>
 */
 
@interface Authorize_Device : WSGeneratedObj
 
// update the parameter list for the invocation.
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla|Authorize_Device */) in_parameters;
 
// result returns an id from the reply dictionary as specified by the WSDL.
- (id) resultValue;
 
@end; /* Authorize_Device */
 
 
/*-
 *   Method Name:  Login
 * Documentation:  <no documentation>
 */
 
@interface Login : WSGeneratedObj
 
// update the parameter list for the invocation.
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters;
 
// result returns an id from the reply dictionary as specified by the WSDL.
- (id) resultValue;
 
@end; /* Login */
 
 
/*-
 *   Method Name:  Authorize_Device
 * Documentation:  <no documentation>
 */
 
@interface Authorize_Device : WSGeneratedObj
 
// update the parameter list for the invocation.
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Authorize_Device */) in_parameters;
 
// result returns an id from the reply dictionary as specified by the WSDL.
- (id) resultValue;
 
@end; /* Authorize_Device */
 
 
/*-
 *   Method Name:  Login
 * Documentation:  <no documentation>
 */
 
@interface Login : WSGeneratedObj
 
// update the parameter list for the invocation.
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters;
 
// result returns an id from the reply dictionary as specified by the WSDL.
- (id) resultValue;
 
@end; /* Login */
 
 
/*-
 * Web Service:  HHU_Authorization
 */
@interface HHU_AuthorizationService : NSObject 
 
+ (id) Authorize_Device:(CFTypeRef /* Complex type http://localhost/bla/|Authorize_Device */) in_parameters;
+ (id) Login:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters;
 
@end;
 
 
#endif /* __HHU_Authorization__ */
/*-
 * End of WSDL document at http://localhost/bla/HHU_Authorization.asmx?wsdl
 */
 
 
 
 
/*-
 * WSDL stubs for:  http://localhost/bla/HHU_Authorization.asmx?wsdl
 *   Generated by:  d34thd34l3r
 *           Date:  Wed Jul 22 18:58:20 2009
 *        Emitter:  Objective-C
 */
 
#import "HHU_Authorization.h"
 
/*-
 *   Method Name:  Authorize_Device
 * Documentation:  <no documentation>
 */
@implementation Authorize_Device
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Authorize_Device */) in_parameters
{
    id _paramValues[] = {    
        in_parameters,        
    };    
    NSString* _paramNames[] = {    
        @"parameters",        
    };    
    [super setParameters:1 values: _paramValues names: _paramNames];    
}
 
- (id) resultValue
{
    return [[super getResultDictionary] objectForKey: @"parameters"];    
}
 
- (WSMethodInvocationRef) genCreateInvocationRef
{
    return [self createInvocationRef    
               /*endpoint*/: @"http://localhost/bla/HHU_Authorization.asmx"            
                 methodName: @"Authorize_Device"            
                 protocol: (NSString*) kWSSOAP2001Protocol            
            // missing encoding style - defaulting to RPC            
                      style: (NSString*) kWSSOAPStyleRPC            
                 soapAction: @"http://localhost/bla/Authorize_Device"            
            methodNamespace: NULL /* No Method Namespace specified */            
        ];        
}
 
@end; /* Authorize_Device */
 
 
/*-
 *   Method Name:  Login
 * Documentation:  <no documentation>
 */
@implementation Login
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters
{
    id _paramValues[] = {    
        in_parameters,        
    };    
    NSString* _paramNames[] = {    
        @"parameters",        
    };    
    [super setParameters:1 values: _paramValues names: _paramNames];    
}
 
- (id) resultValue
{
    return [[super getResultDictionary] objectForKey: @"parameters"];    
}
 
- (WSMethodInvocationRef) genCreateInvocationRef
{
    return [self createInvocationRef    
               /*endpoint*/: @"http://localhost/bla/HHU_Authorization.asmx"            
                 methodName: @"Login"            
                 protocol: (NSString*) kWSSOAP2001Protocol            
            // missing encoding style - defaulting to RPC            
                      style: (NSString*) kWSSOAPStyleRPC            
                 soapAction: @"http://localhost/bla/Login"            
            methodNamespace: NULL /* No Method Namespace specified */            
        ];        
}
 
@end; /* Login */
 
 
/*-
 *   Method Name:  Authorize_Device
 * Documentation:  <no documentation>
 */
@implementation Authorize_Device
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Authorize_Device */) in_parameters
{
    id _paramValues[] = {    
        in_parameters,        
    };    
    NSString* _paramNames[] = {    
        @"parameters",        
    };    
    [super setParameters:1 values: _paramValues names: _paramNames];    
}
 
- (id) resultValue
{
    return [[super getResultDictionary] objectForKey: @"parameters"];    
}
 
- (WSMethodInvocationRef) genCreateInvocationRef
{
    return [self createInvocationRef    
               /*endpoint*/: @"http://localhost/bla/HHU_Authorization.asmx"            
                 methodName: @"Authorize_Device"            
                 protocol: (NSString*) kWSSOAP2001Protocol            
            // missing encoding style - defaulting to RPC            
                      style: (NSString*) kWSSOAPStyleRPC            
                 soapAction: @"http://localhost/bla/Authorize_Device"            
            methodNamespace: NULL /* No Method Namespace specified */            
        ];        
}
 
@end; /* Authorize_Device */
 
 
/*-
 *   Method Name:  Login
 * Documentation:  <no documentation>
 */
@implementation Login
- (void) setParameters:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters
{
    id _paramValues[] = {    
        in_parameters,        
    };    
    NSString* _paramNames[] = {    
        @"parameters",        
    };    
    [super setParameters:1 values: _paramValues names: _paramNames];    
}
 
- (id) resultValue
{
    return [[super getResultDictionary] objectForKey: @"parameters"];    
}
 
- (WSMethodInvocationRef) genCreateInvocationRef
{
    return [self createInvocationRef    
               /*endpoint*/: @"http://localhost/bla/HHU_Authorization.asmx"            
                 methodName: @"Login"            
                 protocol: (NSString*) kWSSOAP2001Protocol            
            // missing encoding style - defaulting to RPC            
                      style: (NSString*) kWSSOAPStyleRPC            
                 soapAction: @"http://localhost/bla/Login"            
            methodNamespace: NULL /* No Method Namespace specified */            
        ];        
}
 
@end; /* Login */
 
 
 
@implementation HHU_AuthorizationService
 
+ (id) Authorize_Device:(CFTypeRef /* Complex type http://localhost/bla/|Authorize_Device */) in_parameters
{
    id result = NULL;    
    Authorize_Device* _invocation = [[Authorize_Device alloc] init];    
    [_invocation setParameters: in_parameters];    
    result = [[_invocation resultValue] retain];    
    [_invocation release];    
    return result;    
}
 
 
+ (id) Login:(CFTypeRef /* Complex type http://localhost/bla/|Login */) in_parameters
{
    id result = NULL;    
    Login* _invocation = [[Login alloc] init];    
    [_invocation setParameters: in_parameters];    
    result = [[_invocation resultValue] retain];    
    [_invocation release];    
    return result;    
}
 
 
 
@end;
 
 
/*-
 * End of WSDL document at
http://localhost/bla/HHU_Authorization.asmx?wsdl
 */

Open in new window

Error.jpg
Sorry, I am learning Iphone SDK also and even greener than you!    Try posting another question on that topic.
I have actually made a Dataset object / class for pulling down from web services, maybe it will save some people some time?

http://grabalife.com/2009/10/19/using-net-web-services-and-dataset-objects-in-your-iphone-app/