Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-22-2009, 08:12 AM   #51 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 16
Default Problem passing xml data to web service

Quote:
Originally Posted by habdelra View Post
if the 2 locations are not that far from eachother a little simple trigometry will work. Checkout this website: Distance Calculation latitude longitude global database lists
Hello :
I used the code posted in this thread. It helped me a lot.
But now I am facing an issue please help me.
I want to send data to web service in the form of xml like

<son>
<child name="XYZ">
</son>
and get back some information related to child.
But 0 byte response is received please help me in fixing this issue
Thanks in advance
ashwanik04 is offline   Reply With Quote
Old 04-22-2009, 08:26 AM   #52 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 87
Default

Quote:
Originally Posted by ashwanik04 View Post
Hello :
I used the code posted in this thread. It helped me a lot.
But now I am facing an issue please help me.
I want to send data to web service in the form of xml like

<son>
<child name="XYZ">
</son>
and get back some information related to child.
But 0 byte response is received please help me in fixing this issue
Thanks in advance
Use http post method here in IPhone to send data and add one aspx page in ur webservice and save that post data in to a xml file in page load of aspx page like this.


protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
int streamLength;
int streamRead;
Stream s = Request.InputStream;
streamLength = Convert.ToInt32(s.Length);
Byte[] streamArray = new Byte[streamLength];

streamRead = s.Read(streamArray, 0, streamLength);
for (int i = 0; i < streamLength; i++)
{
sb.Append(Convert.ToChar(streamArray[i]));
}

string strFilePath = Request.PhysicalApplicationPath;
strFilePath = strFilePath + "\\iPhone.xml";

FileStream fs = new FileStream(strFilePath, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(sb.ToString());
sw.Flush();
sw.Close();
fs.Close();
}

cheers,
Gagandeep
gagandeepb is offline   Reply With Quote
Old 04-22-2009, 08:31 AM   #53 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 16
Default Send xml data to web service

Quote:
Originally Posted by gagandeepb View Post
Use http post method here in IPhone to send data and add one aspx page in ur webservice and save that post data in to a xml file in page load of aspx page like this.


protected void Page_Load(object sender, EventArgs e)
{
StringBuilder sb = new StringBuilder();
int streamLength;
int streamRead;
Stream s = Request.InputStream;
streamLength = Convert.ToInt32(s.Length);
Byte[] streamArray = new Byte[streamLength];

streamRead = s.Read(streamArray, 0, streamLength);
for (int i = 0; i < streamLength; i++)
{
sb.Append(Convert.ToChar(streamArray[i]));
}

string strFilePath = Request.PhysicalApplicationPath;
strFilePath = strFilePath + "\\iPhone.xml";

FileStream fs = new FileStream(strFilePath, FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write(sb.ToString());
sw.Flush();
sw.Close();
fs.Close();
}

cheers,
Gagandeep
Thanks for your reply.
I forgot to say that the web service is external, I mean it cannot be changed.
So, is there any other way
ashwanik04 is offline   Reply With Quote
Old 04-22-2009, 08:35 AM   #54 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 87
Default

Quote:
Originally Posted by ashwanik04 View Post
Thanks for your reply.
I forgot to say that the web service is external, I mean it cannot be changed.
So, is there any other way
what is the parameter type in your webservice method. Is it sting?
gagandeepb is offline   Reply With Quote
Old 04-22-2009, 08:50 AM   #55 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 16
Default

Quote:
Originally Posted by gagandeepb View Post
what is the parameter type in your webservice method. Is it sting?
Yes it is string.
ashwanik04 is offline   Reply With Quote
Old 04-22-2009, 09:29 AM   #56 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 87
Default

Quote:
Originally Posted by ashwanik04 View Post
Yes it is string.
Then see the post written by "nait" in this same thread he showed how to call soap web service methods with thier string parameter.
gagandeepb is offline   Reply With Quote
Old 04-23-2009, 12:49 AM   #57 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 16
Default Order of calling web service

Quote:
Originally Posted by Trilitech View Post
Like many others I wrote an app that was heavily dependent on asp.net SOAP web services that worked great in the simulator and then got hit with the surprise that the CoreServices library that contained all the web service functionality wasn't actually available on the iPhone. I'm still holding out hope this functionality will be added eventually.

All my code was dependant on receiving back the NSDictionary and NSArray object tree, and I didn't want to rewrite it all, so I created a wrapper to emulate the missing SOAP functionality by passing the request over REST. This allowed me to just swap out the method I was using for the webservice calls and keep the rest of the code the same. I thought I'd share it for anyone else in the same boat.

Fortunately asp.net already supports REST style requests (I didn't realize this before today), so no changes were needed on the web server side.

To demonstrate here the call to a simple method called "SayHello". You pass in name and it returns a single item called "string" that contains "Hello [yourname]". The code will work with more complex objects with child properties as well, and return them as NSDictionary and NSArray objects, but for simplicity I'm using "SayHello".

Code:
NSArray *keys = [NSArray arrayWithObjects:@"userName", nil];
NSArray *objects = [NSArray arrayWithObjects:@"jeremy", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSDictionary *wsResponse=[WebServices callRestService:@"SayHello" :params];

NSString *responseString=[wsResponse objectForKey:@"string"];
callRestService is a helper method I created in a class called Webservices. This code was exactly the same before except the helper method was called callSoapService.

WebServices.m contains two methods. getRestUrl just appends all the method parameters into a url to make the REST request. callRestService uses the build-in NSXMLParser class to retrieve the xml and sends it to a custom class called XmlParser to handle the callbacks and create the NSDictionary result,

WebServices.m
Code:
+(id)callRestService: (NSString *) methodName : (NSDictionary *) params
{
	NSURL *url=[WebServices getRestUrl: methodName : params];
	XmlParser *xmlParser = [[XmlParser alloc] init];
	
	NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	[parser setDelegate:xmlParser];
	[parser setShouldProcessNamespaces:NO];
	[parser setShouldReportNamespacePrefixes:NO];
	[parser setShouldResolveExternalEntities:NO];
	[parser parse];
	[parser release];
	return xmlParser.result;
}

+(NSURL *)getRestUrl: (NSString *) methodName : (NSDictionary *) params
{
	NSString *url=@"http://services.mywebsite.com/mywebservice.asmx/";
	url=[url stringByAppendingString:methodName];
	
	BOOL firstKey=TRUE;
	for (NSString *key in params)
	{
		NSString *value=[params objectForKey:key];
		if (firstKey) url=[url stringByAppendingString:@"?"]; else url=[url stringByAppendingString:@"&"];
		url=[url stringByAppendingString:key];
		url=[url stringByAppendingString:@"="];
		url=[url stringByAppendingString:value];
		firstKey=FALSE;
	}
	return [NSURL URLWithString:url];
}

The final step is to create the XmlParser handler. This class keeps track of each open and close tag to build an object tree containing NSMutableArray NSMutableDictionary and NSString objects.

XmlParser.h
Code:
#import <Foundation/Foundation.h>


@interface XmlParser : NSObject {
	NSMutableDictionary *result;
	NSString *currentElementName;
	NSString *currentElementValue;
	NSMutableArray *parentArray;
}

@property (nonatomic, retain) NSMutableDictionary *result;
@property (nonatomic, retain) NSString *currentElementName;
@property (nonatomic, retain) NSString *currentElementValue;
@property (nonatomic, retain) NSMutableArray *parentArray;


- (void)parserDidStartDocument:(NSXMLParser *)parser;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

@end

XmlParser.m
Code:
#import "XmlParser.h"


@implementation XmlParser
@synthesize result;
@synthesize currentElementName;
@synthesize currentElementValue;
@synthesize parentArray;


- (void)parserDidStartDocument:(NSXMLParser *)parser
{
	result=[[NSMutableDictionary alloc] init];
	parentArray=[[NSMutableArray alloc] init];
	[parentArray addObject:result];
	currentElementName=@"";
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	if (qName) {
		elementName = qName;
	}
	currentElementValue=@"";
	if (currentElementName!=@"")
	{
		id newParent=NULL;
		if ([currentElementName isLike:@"*Array*"])
		{
			newParent=[[NSMutableArray alloc] init];
		} else {
			newParent=[[NSMutableDictionary alloc] init];
		}
		[parentArray addObject:newParent];
	}
	currentElementName=elementName;
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{     
	if (qName) {
		elementName = qName;
	}
	
	if (currentElementName==@"")
	{
		//We're adding a container with children.  Add it to the parent and remove this item fromt he parentArray
		int currentIndex=[parentArray count]-1;
		int parentIndex=currentIndex - 1;
		id currentChild=[parentArray objectAtIndex:currentIndex];
		id currentParent=[parentArray objectAtIndex:parentIndex];
		
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentChild];
		} else {
			[currentParent setObject:currentChild forKey:elementName];
		}
		
		[parentArray removeObjectAtIndex:currentIndex];
	} else {
		//We're adding a simple type element
		int currentIndex=[parentArray count]-1;
		id currentParent=[parentArray objectAtIndex:currentIndex];
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentElementValue];
		} else {
			[currentParent setObject:currentElementValue forKey:currentElementName];
		}
	}
	currentElementName=@"";
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	currentElementValue=string;
}

@end
That's it. I'm sure it's not the cleanest code (This is my very first XCode app) and there may be a better way of doing this, but it saved me from having to rewrite all my code that was retrieving data from SOAP services. I've seen tons of other people with the same problem and no solutions so far. I hope this helps.
Hello:
I followed your approach. I am able to call the web service. But I am having an issue please help me in that.

I have an application which when starts first time on the device, then it calls a web service which gives some data and stores it in a xml file for future use. After this call, I am reading the xml file and showing the data in table view. But for the first time, the file is not created before the view load, so no data is displayed. But if I run the application next time, as the file has been created , the table view displays the data.
My problem is that even in the first time also the data should be created before the view load and the data is displayed in the table view.

Please help me in this issue.
ashwanik04 is offline   Reply With Quote
Old 04-24-2009, 02:55 PM   #58 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default

I noticed one person mentioned using RESTful web services instead of SOAP. This is my plan as well. My question is...are you still streaming XML or are you using something more lightweight like JSON?

Thanks,
Ci-Ci
cici is offline   Reply With Quote
Old 04-29-2009, 12:05 AM   #59 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default Parser issue

Hello everyone

For my iphone application I need to request data about an object through a webservice.
I've used the code provided in this thread to do basic GET Request.
In fact, for now on, it just request an XML file located on a webserver (http://.../lait.xml).

Here's the XML i'm supposed to parse :
Code:
<?xml version="1.0" encoding="UTF-8"?>
<object>
	<id>126</id> <!-- The object desserved has the id 126 in this kwys instance -->
	<name>Milk</name> <!-- It is codenamed Milk -->
	<information lang="fr"> <!-- We asked for french information -->
		<title>Le lait</title> <!-- The title is the localized object's name -->
		<!-- Here be the 3 types of content (for now): text, media, and link. -->
		<!-- Each one may appear as many time as possible, in any order. -->
		<text> <!-- A text entry is a caption followed by contents -->
			<caption>Introduction</caption>
			<!-- There must be at least one content Element. -->
			<content>
				Le lait est une boisson de couleur généralement blanchâtre
				produite par
				les mammifères femelles (y compris les monotrèmes).
				Cette capacité
				des femelles est une des caractéristiques définissant
				les mammifères.
				Le lait est produit par les cellules sécrétrices des
				glandes
				contenues dans les mamelles. Le lait sécrété dans les
				premiers jours
				après la parturition s'appelle le colostrum.
			</content>
			<content>
				La fonction première du lait est de nourrir la progéniture
				jusqu'à ce
				qu'elle soit sevrée, c'est-à-dire capable de digérer
				d'autres
				aliments. Dans la plupart des civilisations humaines, le
				lait des
				animaux (eux-mêmes mammifères) domestiques (vache, brebis,
				chèvre,
				jument, dri, chamelle, dromadaire, bufflonne) est couramment
				consommé.
			</content>
			<content>
				Par analogie, on utilise également le terme de lait pour
				désigner plusieurs boissons de consistance et/ou d'apparence
				similaires et produites à base de végétaux, comme le lait de soja,
				de coco, de riz, d'amande, d'avoine ou encore de pistache.
			</content>
		</text>
		<media> <!-- Media refers to static media (picture) or dynamic/rich (video, ...). -->
			<caption>Une fille pas douée en train de tout foutre à coté.</caption>
			<href>http://upload.wikimedia.org/wikipedia/commons/5/59/MilkMaid.JPG</href>
		</media>
		<link> <!-- A link may refer to an external source, like this french wikipedia article. -->
			<caption>Le lait sur wikipedia.</caption>
			<href>http://fr.wikipedia.org/wiki/Lait</href>
		</link>
		<link> <!-- A link may also refer to another internal object, like this milk box. -->
			<caption>La brique de lait.</caption>
			<id>956</id>
		</link>
	</information>
</object>
The webrequest seems ok and here's the result from the NSDictionnary after going through server:

Code:
Response : {
    object =     {
        id = 126;
        information =         {
            link =             {
                caption = "La brique de lait.";
                id = 956;
            };
            media =             {
                caption = "\U00e9e en train de tout foutre \U00e0 cot\U00e9.";
                href = "http://upload.wikimedia.org/wikipedia/commons/5/59/MilkMaid.JPG";
            };
            text =             {
                caption = Introduction;
                content = "\U00e9galement le terme de lait pour\n\t\t\t\td\U00e9signer plusieurs boissons de consistance et/ou d'apparence\n\t\t\t\tsimilaires et produites \U00e0 base de v\U00e9g\U00e9taux, comme le lait de soja,\n\t\t\t\tde coco, de riz, d'amande, d'avoine ou encore de pistache.\n\t\t\t";
            };
            title = "Le lait";
        };
        name = Milk;
    };
}
The only thing is that the XMLParser seems to skip every node type he has already been going through (like <content> for example).

Could anyone tell me if there's a modification to do in the parser to correct that issue ?
I repost the parser .m file:
Code:
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
	result=[[NSMutableDictionary alloc] init];
	parentArray=[[NSMutableArray alloc] init];
	[parentArray addObject:result];
	currentElementName=@"";
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	if (qName) {
		elementName = qName;
	}
	currentElementValue=@"";
	if (currentElementName!=@"")
	{
		id newParent=NULL;
		if ([currentElementName isEqualToString:@"*Array*"])
		{
			newParent=[[NSMutableArray alloc] init];
		} else {
			newParent=[[NSMutableDictionary alloc] init];
		}
		[parentArray addObject:newParent];
	}
	currentElementName=elementName;
	NSLog(@"Name %@", currentElementName); //to check the parser is really going through every node received from the web and it does. It just doesn't store 2 similar type of node.
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{     
	if (qName) {
		elementName = qName;
	}
	
	if (currentElementName==@"")
	{
		//We're adding a container with children.  Add it to the parent and remove this item fromt he parentArray
		int currentIndex=[parentArray count]-1;
		int parentIndex=currentIndex - 1;
		id currentChild=[parentArray objectAtIndex:currentIndex];
		id currentParent=[parentArray objectAtIndex:parentIndex];
		
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentChild];
		} else {
			[currentParent setObject:currentChild forKey:elementName];
		}
		
		[parentArray removeObjectAtIndex:currentIndex];
	} else {
		//We're adding a simple type element
		int currentIndex=[parentArray count]-1;
		id currentParent=[parentArray objectAtIndex:currentIndex];
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentElementValue];
		} else {
			[currentParent setObject:currentElementValue forKey:currentElementName];
		}
	}
	currentElementName=@"";
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	currentElementValue=string;
}
Hope someone can help. I just want a generic xml parser which gives me back a big NSDictionnary i can go through and get data.

Thanks
Topper is offline   Reply With Quote
Old 04-29-2009, 02:09 AM   #60 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 2
Default

Mmmh after reading what i just wrote i suppose it's just the way i try to access the data that cause problems.
Could anyone tell me how i'm supposed to access the "caption" field of a link ?
I think i have to get a NSMutableArray from "information" with the key "link" then every row should be a NSDictionary and i should be able to query it by a simple objectForKey:@"caption" right ?

Last edited by Topper; 04-29-2009 at 05:20 AM.
Topper is offline   Reply With Quote
Old 04-30-2009, 01:37 PM   #61 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 1
Default Secure it?

How is everyone securing their per-user access to the web service and managing a server-side session for that user?

i.e. assuming encryption is handled by SSL -- how do you set the user session context on the web server? By http authentication, or actually passing a username/password pair into a 'logon' operation on the web-service and a token afterwards? the userid/pw pair every operation call?

Any examples appreciated.

Last edited by nwhiteside; 04-30-2009 at 01:52 PM.
nwhiteside is offline   Reply With Quote
Old 05-11-2009, 10:08 AM   #62 (permalink)
New Member
 
Join Date: May 2009
Posts: 1
Default

Does anyone know how to obtain the attributes of an xml tag invoquing a SOAP webservice?
I'm able to get the NSDictionary, but the attributes are missing.

Example:

XML returned by the service:
<son>
<child name="XYZ">
</son>

If I use the WSMethodInvocationInvoke method to invoque it, I will get the NSDictionary whith a "son" object but I wont get the "child" name attribute so it will be nil

but if the webservice returns
<son>
<child>XYZ</son>
</son>

I will get child the object with a value of XYZ

Any clue?
ariel is offline   Reply With Quote
Old 06-19-2009, 05:11 AM   #63 (permalink)
New Member
 
Join Date: May 2009
Posts: 10
Default how to read a double value from the Webservice?

I am trying to read a double value returned by a webservice using NSXMLParser. In the event parser didEndElement, I am getting the correct value. But in the final output, the value gets reset to zero.

Could you please help me in this regard.....

Ramesh.

Quote:
Originally Posted by realberen View Post
Thanks for the post. Just wondering, if you're interacting more, like sending data like you would normally do in the SOAP envelope, how do you do that in this scenario?

Cheers

Nik
prameshu is offline   Reply With Quote
Old 06-27-2009, 06:51 PM   #64 (permalink)
Registered Member
 
Join Date: Feb 2009
Posts: 87
Default

Quote:
Originally Posted by varchar View Post
As they say: "That's what discussion boards are for...."

Glad I can help....
Im looking to access a webservice to pull data into a tableview on my iphone app for the user to scroll through. Then when they find a title they like, they can select the title in the tableview and be taken to the image that is also being stored on the webserver.

Would you know where i can get some sample code for this?

this seems to be the thread for this stuff so any help would be greatly appreciated!

Thanks
Paul

Last edited by pmvinuelas; 06-27-2009 at 07:07 PM.
pmvinuelas is offline   Reply With Quote
Old 07-24-2009, 03:43 PM   #65 (permalink)
New Member
 
Join Date: Jul 2009
Posts: 1
Default Sample

Can you send me the zip file for this code?

Thanks in advance!

Rob
robbonner@mac.com
rbonner is offline   Reply With Quote
Old 08-13-2009, 12:51 PM   #66 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 5
Default Handling of an authentication key that somes back from a SOAP Login Method?

Hi, Thanks very much for posting these examples. These and the threads of replies have been very useful in getting a successful connection to a webservice I am trying to use. I did manage to call a Login method on my
service which sends back a session key. I assume that somehow I need to be sure to include this key in future requests to various methods (so it will know which session to use) What I am not sure is how to send the key. Does it get wrapped into a SOAP header? or does it somehow get associated with the NSURLRequest object? any thoughts, advice, examples appreciated.

dealyb is offline   Reply With Quote
Old 08-14-2009, 07:13 AM   #67 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 1
Default

Hi, i have one leak with xmlParser, and i dont know how fix it

Code:
XMLParser *xmlParser = [[XMLParser alloc] init];
// ... more code ...
return xmlParser.parentArray
And this is the method:

Code:
+(id)callRestService:  (NSString *) url: (NSString *) methodName: (NSArray *) keys: (NSArray *) objects
{
	NSURL *theURL=[WebServices generateWebServiceHTTPGetURL : url: methodName: keys: objects];
	
	XmlParser *xmlParser = [[XmlParser alloc] init];
	
	NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:theURL];
	[parser setDelegate:xmlParser];
	[parser setShouldProcessNamespaces:NO];
	[parser setShouldReportNamespacePrefixes:NO];
	[parser setShouldResolveExternalEntities:NO];
	[parser parse];
	[parser release];

	return xmlParser.parentArray;
}
xmlParser not is released in the code, if i proof with autorelease but not work

Pls, can someone help me?

Thank you so much.
FORTUN is offline   Reply With Quote
Old 08-26-2009, 12:01 PM   #68 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 2
Default

Quote:
Originally Posted by Trilitech View Post
Fortunately asp.net already supports REST style requests (I didn't realize this before today), so no changes were needed on the web server side.
Well maybe one change...

This was not working for me. Then I realized it WAS working only from the same development machine that was running the service. You can see this feature in action on the test web service pages that ASP.NET builds automatically.

In order to make this feature of ASP.NET accessible to remote machines I had to add this to my web.config file in ASP.NET.

Code:
<webServices>
    <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
    </protocols>
</webServices>
bclery is offline   Reply With Quote
Old 03-25-2010, 07:07 AM   #69 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: netherlands
Posts: 10
Send a message via MSN to saimun
Default

wow this is very helpful, n i need to build something like blackE had, is there any source code example of what balckE had to dl??
saimun is offline   Reply With Quote
Old 03-27-2010, 02:57 AM   #70 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
Default call webservice from iphone app

Hi,

I am trying to call a webservice from iphone. I want to know how to formulate soap requests to be sent to the webservice .pls help.i m a newbie...


@WebMethod(operationName = "CheckAuthenticationLogin")
public String CheckAuthenticationLogin(@WebParam(name = "loginxml") String loginxml, @WebParam(name = "key") String key)
nicholas is offline   Reply With Quote
Old 03-27-2010, 02:17 PM   #71 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 92
Default

I highly recommend looking at the SOAP service code generator SudzC (alpha) | clean source code from your web services. The author is really helpful too.

I hope this helps people get around the woeful support for SOAP in the SDK.
funkyspider is offline   Reply With Quote
Old 07-02-2010, 09:11 AM   #72 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 43
Default

That is I am need thx friends
ashishjraval is offline   Reply With Quote
Old 07-29-2010, 06:29 AM   #73 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 4
Default

Quote:
Originally Posted by varchar View Post
Let me know what you want to do... I can write the code for you if you wish....
can i use a web service built in java? What will i have to do?
I have a wsdl file for the web-service. How can i consume it?
nepster is offline   Reply With Quote
Old 09-21-2010, 09:13 AM   #74 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 51
Default

Quote:
Originally Posted by Trilitech View Post
Like many others I wrote an app that was heavily dependent on asp.net SOAP web services that worked great in the simulator and then got hit with the surprise that the CoreServices library that contained all the web service functionality wasn't actually available on the iPhone. I'm still holding out hope this functionality will be added eventually.

All my code was dependant on receiving back the NSDictionary and NSArray object tree, and I didn't want to rewrite it all, so I created a wrapper to emulate the missing SOAP functionality by passing the request over REST. This allowed me to just swap out the method I was using for the webservice calls and keep the rest of the code the same. I thought I'd share it for anyone else in the same boat.

Fortunately asp.net already supports REST style requests (I didn't realize this before today), so no changes were needed on the web server side.

To demonstrate here the call to a simple method called "SayHello". You pass in name and it returns a single item called "string" that contains "Hello [yourname]". The code will work with more complex objects with child properties as well, and return them as NSDictionary and NSArray objects, but for simplicity I'm using "SayHello".

Code:
NSArray *keys = [NSArray arrayWithObjects:@"userName", nil];
NSArray *objects = [NSArray arrayWithObjects:@"jeremy", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSDictionary *wsResponse=[WebServices callRestService:@"SayHello" :params];

NSString *responseString=[wsResponse objectForKey:@"string"];
callRestService is a helper method I created in a class called Webservices. This code was exactly the same before except the helper method was called callSoapService.

WebServices.m contains two methods. getRestUrl just appends all the method parameters into a url to make the REST request. callRestService uses the build-in NSXMLParser class to retrieve the xml and sends it to a custom class called XmlParser to handle the callbacks and create the NSDictionary result,

WebServices.m
Code:
+(id)callRestService: (NSString *) methodName : (NSDictionary *) params
{
	NSURL *url=[WebServices getRestUrl: methodName : params];
	XmlParser *xmlParser = [[XmlParser alloc] init];
	
	NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	[parser setDelegate:xmlParser];
	[parser setShouldProcessNamespaces:NO];
	[parser setShouldReportNamespacePrefixes:NO];
	[parser setShouldResolveExternalEntities:NO];
	[parser parse];
	[parser release];
	return xmlParser.result;
}

+(NSURL *)getRestUrl: (NSString *) methodName : (NSDictionary *) params
{
	NSString *url=@"http://services.mywebsite.com/mywebservice.asmx/";
	url=[url stringByAppendingString:methodName];
	
	BOOL firstKey=TRUE;
	for (NSString *key in params)
	{
		NSString *value=[params objectForKey:key];
		if (firstKey) url=[url stringByAppendingString:@"?"]; else url=[url stringByAppendingString:@"&"];
		url=[url stringByAppendingString:key];
		url=[url stringByAppendingString:@"="];
		url=[url stringByAppendingString:value];
		firstKey=FALSE;
	}
	return [NSURL URLWithString:url];
}

The final step is to create the XmlParser handler. This class keeps track of each open and close tag to build an object tree containing NSMutableArray NSMutableDictionary and NSString objects.

XmlParser.h
Code:
#import <Foundation/Foundation.h>


@interface XmlParser : NSObject {
	NSMutableDictionary *result;
	NSString *currentElementName;
	NSString *currentElementValue;
	NSMutableArray *parentArray;
}

@property (nonatomic, retain) NSMutableDictionary *result;
@property (nonatomic, retain) NSString *currentElementName;
@property (nonatomic, retain) NSString *currentElementValue;
@property (nonatomic, retain) NSMutableArray *parentArray;


- (void)parserDidStartDocument:(NSXMLParser *)parser;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName;
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;

@end

XmlParser.m
Code:
#import "XmlParser.h"


@implementation XmlParser
@synthesize result;
@synthesize currentElementName;
@synthesize currentElementValue;
@synthesize parentArray;


- (void)parserDidStartDocument:(NSXMLParser *)parser
{
	result=[[NSMutableDictionary alloc] init];
	parentArray=[[NSMutableArray alloc] init];
	[parentArray addObject:result];
	currentElementName=@"";
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
	if (qName) {
		elementName = qName;
	}
	currentElementValue=@"";
	if (currentElementName!=@"")
	{
		id newParent=NULL;
		if ([currentElementName isLike:@"*Array*"])
		{
			newParent=[[NSMutableArray alloc] init];
		} else {
			newParent=[[NSMutableDictionary alloc] init];
		}
		[parentArray addObject:newParent];
	}
	currentElementName=elementName;
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{     
	if (qName) {
		elementName = qName;
	}
	
	if (currentElementName==@"")
	{
		//We're adding a container with children.  Add it to the parent and remove this item fromt he parentArray
		int currentIndex=[parentArray count]-1;
		int parentIndex=currentIndex - 1;
		id currentChild=[parentArray objectAtIndex:currentIndex];
		id currentParent=[parentArray objectAtIndex:parentIndex];
		
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentChild];
		} else {
			[currentParent setObject:currentChild forKey:elementName];
		}
		
		[parentArray removeObjectAtIndex:currentIndex];
	} else {
		//We're adding a simple type element
		int currentIndex=[parentArray count]-1;
		id currentParent=[parentArray objectAtIndex:currentIndex];
		if ([currentParent isKindOfClass:[NSMutableArray class]])
		{
			[currentParent addObject:currentElementValue];
		} else {
			[currentParent setObject:currentElementValue forKey:currentElementName];
		}
	}
	currentElementName=@"";
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
	currentElementValue=string;
}

@end
That's it. I'm sure it's not the cleanest code (This is my very first XCode app) and there may be a better way of doing this, but it saved me from having to rewrite all my code that was retrieving data from SOAP services. I've seen tons of other people with the same problem and no solutions so far. I hope this helps.
Hi,can u give me the code..i have gone through ur code,but not getting anything as output.please i m new toi iphone world..help me!!!
pinu is offline   Reply With Quote
Old 10-04-2010, 02:51 AM   #75 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 15
Default

Best tutorial for Soap Services....

iPhone Programming Tutorial – Intro to SOAP Web Services | iCodeBlog
kuldeepsidhu is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 157,869
Threads: 88,917
Posts: 379,300
Top Poster: BrianSlick (7,072)
Welcome to our newest member, homasen
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0