Solved

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

Posted on 2009-07-15
14
1,488 Views
Last Modified: 2012-05-07
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.

0
Comment
Question by:d34thd34l34r
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
So is the .net web service return a DataSet or DataTable object?

What is the method signature (WSDL)?
0
 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
Yes
0
 
LVL 30

Expert Comment

by:Alexandre Simões
Comment Utility
"Yes" is a pretty good and explaining answer to witch I can just say "Thanks!"
0
 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
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.

0
 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
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.
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
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
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
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?
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
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.
0
 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
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...
0
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
Comment Utility
You don't have to use the .Net xml serializer because it is already being done.  If you look at the sample I created, the WSDL says it will return a XML object

See lines 13-26:
      <s:element name="HelloWorldResponse">

        <s:complexType>

          <s:sequence>

            <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult">

              <s:complexType>

                <s:sequence>

                  <s:element ref="s:schema" />

                  <s:any />

                </s:sequence>

              </s:complexType>

            </s:element>

          </s:sequence>

        </s:complexType>

      </s:element>

Open in new window

0
 
LVL 2

Author Comment

by:d34thd34l34r
Comment Utility
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
0
 
LVL 21

Expert Comment

by:MogalManic
Comment Utility
Sorry, I am learning Iphone SDK also and even greener than you!    Try posting another question on that topic.
0
 

Expert Comment

by:ImperiumDev
Comment Utility
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/
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now