Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 09-29-2008, 12:23 PM   #26 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 3
Default

I've tried this, several times over, with WCF and .net 2.0 asp.net web services, and I can't get it to work. The iphone code works just fine, but I can't find out how to get the web service to accept calls over GET. Google turns up nothing particularly useful, and digging through the settings for the project, IIS, and other system settings doesn't turn anything up either. I figure I must just be overlooking something. All I can find is stuff saying "turn off POST and GET to your .net web services" as they are pretty insecure. I am in the process of writing an actual library for soap calls as opposed to rest, but I'm on a really tight schedule and if I can get this to work, I would rather use it.

Trilitech, thanks a ton for posting this information. It seems your efforts are appreciated by many. You're the first hit for the search string "soap iphone rest" in google .
nait is offline   Reply With Quote
Old 09-30-2008, 01:14 AM   #27 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

I tried to establish a connection with a request:
Code:
- (NSMutableData *)createRequest:(NSString *)city {
	NSMutableData *myMutableData;
	NSMutableString *sRequest = [[NSMutableString alloc] init];
	[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
	[sRequest appendString:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
	[sRequest appendString:@"<soap:Body>"];
    [sRequest appendString:@"<GetWeather xmlns=\"http://litwinconsulting.com/webservices/\">"];
	[sRequest appendString:@"<City>"];
	[sRequest appendString:city];
	[sRequest appendString:@"</City>"];
    [sRequest appendString:@"</GetWeather>"];
	[sRequest appendString:@"</soap:Body>"];
	[sRequest appendString:@"</soap:Envelope>"];
	
	NSURL *weatherServiceURL = [NSURL URLWithString:@"http://litwinconsulting.com/webservices/GetWeather"];
	
	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:weatherServiceURL];
	 
	 [request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"];
	 [request addValue:@"http://litwinconsulting.com/webservices/GetWeather" forHTTPHeaderField:@"SOAPAction"]; 
	
	 [request setHTTPMethod:@"POST"];
	 
	 [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
	
	NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	 
	if (conn) {
		myMutableData = [[NSMutableData data] retain];
		//NSLog(@"Conn is true");
	}
	[NSURLConnection connectionWithRequest:request delegate:self];
	
	NSError *WSerror;
	NSURLResponse *WSresponse;
	
	myMutableData = [NSURLConnection sendSynchronousRequest:request
					  returningResponse:&WSresponse error:&WSerror];


	return myMutableData;
	
}
and tried to parse the result:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	
	[myText setText:@"0"];
	
    // Uncomment the following line to add the Edit button to the navigation bar.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
	SOAPRequest *request = [[SOAPRequest alloc] init];
	
	NSData *myData = [[NSData alloc] initWithData:[request createRequest:@"Vienna"]];
	
	NSXMLParser *parser = [[NSXMLParser alloc] initWithData:myData];
	[parser setShouldProcessNamespaces:NO];
	[parser setShouldReportNamespacePrefixes:NO];
	[parser setShouldResolveExternalEntities:NO];
	
	[parser parse];
	
	[parser release];
	
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI
 qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributDict {
	NSLog(@"Found element %@", elementName);
	
	if ([elementName isEqualToString:@"GetWeatherResult"]) {
		[myText setText:elementName];
	}
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
	[myText setText:string];
}		
		
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
 qualifiedName:(NSString *)qName {
	
}

Im not sure if i use the parser correct but the 3 parser methods are never called either.

Any idea?
Black Scyther is offline   Reply With Quote
Old 09-30-2008, 04:42 AM   #28 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 36
Default

Finally it works!

Ive just forgotten to set the parser delegate. And change the weatherServiceURL to NSURL *weatherServiceURL = [NSURL URLWithString:@"http://litwinconsulting.com/webservices/weather.asmx"];
Black Scyther is offline   Reply With Quote
Old 09-30-2008, 06:35 AM   #29 (permalink)
pdm
New Member
 
Join Date: Aug 2008
Posts: 56
Default

Can anyone share the working code please.

-pdm
pdm is offline   Reply With Quote
Old 10-01-2008, 04:02 PM   #30 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 3
Default

Ok, I could never get a web service or WCF service to accept HTTP GET requests. I did manage to figure out how to manually create a soap envelope and call a 2.0 web service. Here's what the service tells me it needs:
HTML Code:
POST /<my service name>/Service1.asmx HTTP/1.1
Host: <my service host>
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://heyWorld.org/HelloWorld" 

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <HelloWorld xmlns="http://heyWorld.org/">
      <userName>string</userName>
    </HelloWorld>
  </soap:Body>
</soap:Envelope>
The above is from the default asp.net web service you get when creating a new project. I have changed the namespace associated with the function calls from tempuri.org, and added a string parameter to the default HelloWorld function that gets created for you.

The following obj-c creates the soap envelope, creates a NSURLRequest with the necessary content-type etc. (check out everything I do with the 'request' variable), and finally connects and sends the request. I put the NSMutableData variable into an NSString just so I could see it from the debugger, but you can also use this for your parser.
Code:
NSMutableString *sRequest = [[NSMutableString alloc]init];
	//create soap envelope
	[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
	[sRequest appendString:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
	[sRequest appendString:@"<soap:Body>"];
	[sRequest appendString:@"<HelloWorld xmlns=\"http://heyWorld.org/\">"];
	[sRequest appendString:@"<userName>foo</userName>"];
	[sRequest appendString:@"</HelloWorld>"];
	[sRequest appendString:@"</soap:Body>"];
	[sRequest appendString:@"</soap:Envelope>"];
	
	NSURL *myWebserverURL = [NSURL URLWithString:@"http://<my host>/<my project>/Service1.asmx"];
	
	[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL]; 
	
	[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://heyWorld.org/HelloWorld" forHTTPHeaderField:@"SOAPAction"];//this is default tempuri.org, I changed mine in the project
	
	NSString *contentLengthStr = [NSString stringWithFormat:@"%d", [sRequest length]];
	
	[request addValue:contentLengthStr forHTTPHeaderField:@"Content-Length"];
    // Set the action to Post
    [request setHTTPMethod:@"POST"];
    // Set the body
    [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
    // Create the connection
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	NSMutableData *myMutableData;
    // Check the connection object
    if(conn)
    {
		myMutableData=[[NSMutableData data] retain];
    }
    // Make this class the delegate so that the other connection events fire here.
    [NSURLConnection connectionWithRequest:request delegate:self];
	
    NSError *WSerror;
    NSURLResponse *WSresponse;
    // Execute the asp.net Service and return the data in an NSMutableData object
    myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror]; 
	
	//convert the mutabledata to an nsstring so I can see it with the debugger
	NSString *theXml = [[NSString alloc]initWithBytes:[myMutableData mutableBytes] length:[myMutableData length] encoding:NSUTF8StringEncoding];
Be sure to replace <my host> and <my project> where appropriate (and anything else I have up there that's <my *>), and make sure you are using the namespace you have declared for the service (mine is http://heyWorld.org/ and my function is HelloWorld.)
Credit for the above discoveries and most of the code: Tom McCartan
nait is offline   Reply With Quote
Old 10-03-2008, 12:05 AM   #31 (permalink)
Registered Member
 
Join Date: Sep 2008
Posts: 76
Default

Hi Guys,
What if my request xml is too long. Suppose i have 5000 records in a local table and that i want to send to server. Definitely i will not create Soap request like that as mentioned in above posts. What i will prefer is keeping all data in NSData object setting it as a setHTTPBody and then using POST send it to aspx page at server side. Then save whole xml locally over there and then read it in dataset that's all.
gagandeepb is offline   Reply With Quote
Old 10-03-2008, 11:02 AM   #32 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 3
Default

Quote:
Originally Posted by gagandeepb View Post
Hi Guys,
What if my request xml is too long. Suppose i have 5000 records in a local table and that i want to send to server. Definitely i will not create Soap request like that as mentioned in above posts. What i will prefer is keeping all data in NSData object setting it as a setHTTPBody and then using POST send it to aspx page at server side. Then save whole xml locally over there and then read it in dataset that's all.
Sounds like you answered your own question. Create a serialization class that knows what each of the records looks like that will create an NSString containing the xml that holds the data from your NSData object. You can the append that into the appropriate part of the envelope body and call the service that way.

Pseudo Code:
Code:
public class MyDataSerialization
{
 /* maybe static, depends on you */
    public string TurnDataToXml(NSData theData)
    {
      /* maybe static, depends on you */
        foreach (dataUnit in theData)
        {
            //create the appropriate xml nodes in a string you are returning
        }
    return myStringOfXmlNodes;
    }
}
I haven't looked at it yet, but another idea is to use the NSXml object to create your entire envelope programmatically. This is probably the better option as it is specific to what we are trying to do. Using the static strings above is just a simple way to show what we are all trying to accomplish. You can abstract the hell out of what's up there and make it as complex as you like.

Here's some more info about the NSXml object.

Here's the wiki article about serialization. It even has an Objective-C sample (though it looks like they are talking about binary serialization as opposed to xml).
nait is offline   Reply With Quote
Old 10-03-2008, 04:03 PM   #33 (permalink)
New Member
 
Join Date: Oct 2008
Location: Cary NC
Posts: 3
Send a message via ICQ to NCIceman Send a message via AIM to NCIceman Send a message via Yahoo to NCIceman
Default Sample code

Thank you all for the code snippets, this is helping a lot.

I am a new iPhone developer being asked to put together a test app consuming a web service as a proof of concept for my vice president. Unfortunately I have little cocoa or iphone experience, and this is a fairly high-profile test. I really want it to succeed, but I need to make more rapid progress.

Could anyone post sample code for a complete app? I seem to learn the most from reading a whole app. I started with the original posters WebService.m, but am getting warning errors as I don't know how to create the corresponding .h file.

Any links would be helpful.

Thanks!
NCIceman is offline   Reply With Quote
Old 10-10-2008, 05:15 AM   #34 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 12
Question Does iphone sample app SeismicXML any near to the current discussion?

Does iphone sample app SeismicXML any near to the current discussion? It fetches and parses an RSS feed from the USGS.
iphonedev99 is offline   Reply With Quote
Old 10-10-2008, 01:35 PM   #35 (permalink)
New Member
 
Join Date: Oct 2008
Location: Cary NC
Posts: 3
Send a message via ICQ to NCIceman Send a message via AIM to NCIceman Send a message via Yahoo to NCIceman
Default

I am using that as a reference now. I've actually gotten the webservice call portion to work (took me a while to find one that responds to REST requests, went with the Flickr Echo test one). My issue now is in parsing the objects into a Dictionary object....the parse seems to work, but my resulting dictionary only has one entry in it, the top level tag and the body of the xml.

Still plugging away at it...
NCIceman is offline   Reply With Quote
Old 10-10-2008, 09:33 PM   #36 (permalink)
Tylenol is my friend
 
Join Date: Oct 2008
Location: Midwest
Posts: 143
Default

The one thing that has helped me parse the XML streams is to think of it as a water faucet.

As the flow of data comes pouring in from the data source, you redirect it to different pipes on the fly. Evaluating the elements to determine which pipe path you go down.
Store all the water/data in a bucket (storage variable) till you hit the end of the flow (end of the element).

Then dump the bucket into it's final container (class variable, dictionary object, what ever). Then go back up the pipe structure and watch the flow again, till the flow ends.

-------

Back to part of the SOAP discussion.
In my recent research, it is becoming very apparent that REST is growing in popularity and in support. Not just on the iPhone, but also the BlackBerry and Android.

For those of you with SOAP webservices now; You could use different tools to create a REST Wrapper around your SOAP... even if the SOAP is hosted by someone totally else. I was able to do this with .NET fairly quickly, capturing the SOAP calls via the SOAP extensions, and returning just the SOAP Message segment as a raw XML stream.

Granted I am just doing it a temporary solution, as I work on the iPhone product and another team works to add formal REST support to our services.

My suggestion would be to limit the amount of time and energy to stuff SOAP into your iPhone app, but to look at the core webservice to see if it can be converted to REST, or with at least a REST wrapper. Especially if it is going to be a widely used WebService by multiple platform.
Fontano is offline   Reply With Quote
Old 10-11-2008, 11:03 AM   #37 (permalink)
New Member
 
Marco's Avatar
 
Join Date: Apr 2008
Posts: 56
Default

Thank you everyone with all of your sample code, it is appreciated.

I have tried to implement all of the sample code in this thread but I keep getting memory leaks. I have tried to catch them all but to no success.

It looks like the below line is one that Instruments says it has a leak even when released.

Code:
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
... more code here
[parser release];
As anyone here been able to use these sample code without any memory leaks? Is so can you share how you fixed them?

Thank you so much.
__________________
Peace in Christ
Marco Napoli
http://www.ourlovingmother.org
Marco is offline   Reply With Quote
Old 10-13-2008, 03:59 PM   #38 (permalink)
New Member
 
Join Date: Oct 2008
Location: Cary NC
Posts: 3
Send a message via ICQ to NCIceman Send a message via AIM to NCIceman Send a message via Yahoo to NCIceman
Default

Quote:
Originally Posted by Fontano View Post
As the flow of data comes pouring in from the data source, you redirect it to different pipes on the fly. Evaluating the elements to determine which pipe path you go down.
Store all the water/data in a bucket (storage variable) till you hit the end of the flow (end of the element).

Then dump the bucket into it's final container (class variable, dictionary object, what ever). Then go back up the pipe structure and watch the flow again, till the flow ends.
That was the key! Turns out it was parsing it all correctly the whole time, what I did not realize was that my parser was building a dictionary of dictionaries...once I fixed my reference call, I was able to get to the nested object I wanted!

Thanks to all for the samples, just took me a while to get what I was reading!
NCIceman is offline   Reply With Quote
Old 10-13-2008, 11:52 PM   #39 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 12
Question Can anyone run this web service code run for me?

I tried the Trilitech's code the following way but I couldn't get it run for me.

applicationDidFinishLaunching:

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

	NSArray *keys = [NSArray arrayWithObjects:@"UserName", @"Password", nil];
	NSArray *objects = [NSArray arrayWithObjects:@"", @"", nil];
	NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
	NSDictionary *wsResponse=[WebServices callRestService:@"GetGuid" :params];
	
	NSString *responseString=[wsResponse objectForKey:@"string"];

    [window makeKeyAndVisible];
}
WebServices.h

Code:
#import <UIKit/UIKit.h>


@interface WebServices : NSObject {

}

+(id)callRestService: (NSString *) methodName : (NSDictionary *) params;
+(NSURL *)getRestUrl: (NSString *) methodName : (NSDictionary *) params;

@end
WebServices.m

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


@implementation WebServices

+(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://lpsol.com/ws/soap.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];
}
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


But for me the service doesn't seem to return anything. Can anyone favour me here?
iphonedev99 is offline   Reply With Quote
Old 10-14-2008, 12:10 AM   #40 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 12
Question Can anyone run this web service code run for me?

I tried the Trilitech's code the following way but I couldn't get it run for me.

applicationDidFinishLaunching:

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

	NSArray *keys = [NSArray arrayWithObjects:@"UserName", @"Password", nil];
	NSArray *objects = [NSArray arrayWithObjects:@"", @"", nil];
	NSDictionary *params = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
	NSDictionary *wsResponse=[WebServices callRestService:@"GetGuid" :params];
	
	NSString *responseString=[wsResponse objectForKey:@"string"];

    [window makeKeyAndVisible];
}
From the above code the following line

NSDictionary *wsResponse=[WebServices callRestService:@"GetGuid" arams];

returns
Quote:
Printing description of wsResponse:
<CFDictionary 0x460e80 [0xa08141a0]>{type = mutable, count = 1, capacity = 3, pairs = (
0 : <CFString 0x4614e0 [0xa08141a0]>{contents = "ReturnPackage"} = <CFDictionary 0x461080 [0xa08141a0]>{type = mutable, count = 2, capacity = 3, pairs = (
0 : <CFString 0x4614b0 [0xa08141a0]>{contents = "DataPackage"} = <CFDictionary 0x461420 [0xa08141a0]>{type = mutable, count = 1, capacity = 3, pairs = (
1 : <CFString 0xa081f990 [0xa08141a0]>{contents = "GUID"} = <CFString 0x461460 [0xa08141a0]>{contents = "2B55FEF3-78C8-4716-97F1-E0031012A470"}
)}
3 : <CFString 0x461320 [0xa08141a0]>{contents = "ErrorPackage"} = <CFDictionary 0x461010 [0xa08141a0]>{type = mutable, count = 4, capacity = 6, pairs = (
0 : <CFString 0x45a9d0 [0xa08141a0]>{contents = "Flag"} = <CFString 0x45a9e0 [0xa08141a0]>{contents = "False"}
3 : <CFString 0x461120 [0xa08141a0]>{contents = "Message"} = <CFString 0xa0825330 [0xa08141a0]>{contents = "OK"}
4 : <CFString 0x461250 [0xa08141a0]>{contents = "StackTrace"} = <CFString 0x4612b0 [0xa08141a0]>{contents = "N/A"}
6 : <CFString 0x4611b0 [0xa08141a0]>{contents = "AdditionalInfo"} = <CFString 0x461210 [0xa08141a0]>{contents = "N/A"}
)}
)}
)}
iphonedev99 is offline   Reply With Quote
Old 10-14-2008, 12:14 AM   #41 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 12
Thumbs up Can anyone run this web service code run for me?

Sorry, I couldn't observe before. It actually is bringing data . I've to concentrate on parser now I think.
Thanx Trilitech and fellows.
iphonedev99 is offline   Reply With Quote
Old 10-21-2008, 08:05 AM   #42 (permalink)
New Member
 
Join Date: Oct 2008
Posts: 1
Default file post through HTTP

Hi friends,

I am trying to post a file to a ASp page through HTTP.I am able to post file through c# client .But I am not able to post it through cocoa application written in Objective C.
I have used all information I got through google.For instance
I used NSUrl,NSUrlConnection ,NSData classes.Used encoding ..but I am not able to do this.

The posts in above forum is interesting that is why I thought I might get a solution with this forum.

My Asp website is normal with capable of accepting a posted file.
amol is offline   Reply With Quote
Old 10-21-2008, 12:51 PM   #43 (permalink)
New Member
 
Join Date: Sep 2008
Posts: 93
Default

im in!! finally got my contracy completed...

the app is only in the danish store, but here's a link http://tinyurl.com/6yto5c
mbruun is offline   Reply With Quote
Old 11-02-2008, 01:10 PM   #44 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 7
Default

iPhoneDev -- where did you go next. I am in the same spot where everything is compiling and running, but can't seem to 'see' any output.

this is all tied to a button press with MainText as a screen element:

NSArray *keys = [NSArray arrayWithObjects:@"MyName",nil];
NSArray *objects = [NSArray arrayWithObjects:@"MyName", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjectsbjects forKeys:keys];

MainText.text=[wsResponse objectForKey:@"string"];


I stuffed a couple of printf commands in so I know it's all running... just am not too sure why I see no output.

Any ideas?

ps - I am a longterm asp.net guy breaking in. I wrote the webservice on the other end so I know it's all good.


Thanks. Dan Ribar
dribar is offline   Reply With Quote
Old 11-02-2008, 01:18 PM   #45 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 7
Default Sorry - let me try that again...

Here is what I'm running on the button push with no response / errors or anything else:

NSArray *keys = [NSArray arrayWithObjects:@"MyName", nil];
NSArray *objects = [NSArray arrayWithObjects:@"jeremy", nil];
NSDictionary *params = [NSDictionary dictionaryWithObjectsbjects forKeys:keys];
NSDictionary *wsResponse=[WebServices callRestService:@"HelloName" arams];

NSString *responseString=[wsResponse objectForKey:@"string"];

MainText.text = responseString;



Let me know if you have any ideas and thanks in advance...

Dan Ribar
dribar is offline   Reply With Quote
Old 11-02-2008, 02:15 PM   #46 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 7
Default REST vs SOAP?

After doing a bit more work, I found the problem to be my web service not responding to the REST formatted request. I was thrown off a bit by the first post and made the bad assumption that I wouldn't need to make any changes to the SOAP web service.

Is this all correct thought process? Do I need to re-write my SOAP service to respond to a REST call?

My server is IIS V6x all written in Visual Studio.

Thx.
Dan Ribar
dribar is offline   Reply With Quote
Old 11-03-2008, 06:19 PM   #47 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 7
Default Found it >> created a simple handler

OK -- so on the web service end of things, I created a new 'simple handler' in Visual Studio. Added in some code to look for the commandline parameters and now the two are talking. Pretty cool.

I actually spent a lot of time looking for REST examples and my head almost spun off.... ARGHHHH. Sometimes its a lot easier to just write something.

I'm still having some problems parsing through the multiple values in the XML that got returned... but that should be the easy part.

thanks again all for the input.

Dan Ribar
dribar is offline   Reply With Quote
Old 01-12-2009, 03:02 PM   #48 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 1
Default Quotes in an XML/SOAP envelope

I'm sort of a noob here so apologies if this is a bit of a yawn. As seen below, there are quotes used in the XML but this seems to cause an error when compiled. Can anyone direct me toward a way to deal with the quotes as they are necessary in the SOAP request?

Thanks in advance.



Quote:
Originally Posted by nait View Post
Ok, I could never get a web service or WCF service to accept HTTP GET requests. I did manage to figure out how to manually create a soap envelope and call a 2.0 web service. Here's what the service tells me it needs:
HTML Code:
POST /<my service name>/Service1.asmx HTTP/1.1
Host: <my service host>
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://heyWorld.org/HelloWorld" 

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <HelloWorld xmlns="http://heyWorld.org/">
      <userName>string</userName>
    </HelloWorld>
  </soap:Body>
</soap:Envelope>
The above is from the default asp.net web service you get when creating a new project. I have changed the namespace associated with the function calls from tempuri.org, and added a string parameter to the default HelloWorld function that gets created for you.

The following obj-c creates the soap envelope, creates a NSURLRequest with the necessary content-type etc. (check out everything I do with the 'request' variable), and finally connects and sends the request. I put the NSMutableData variable into an NSString just so I could see it from the debugger, but you can also use this for your parser.
Code:
NSMutableString *sRequest = [[NSMutableString alloc]init];
	//create soap envelope
	[sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
	[sRequest appendString:@"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"];
	[sRequest appendString:@"<soap:Body>"];
	[sRequest appendString:@"<HelloWorld xmlns=\"http://heyWorld.org/\">"];
	[sRequest appendString:@"<userName>foo</userName>"];
	[sRequest appendString:@"</HelloWorld>"];
	[sRequest appendString:@"</soap:Body>"];
	[sRequest appendString:@"</soap:Envelope>"];
	
	NSURL *myWebserverURL = [NSURL URLWithString:@"http://<my host>/<my project>/Service1.asmx"];
	
	[NSURLRequest setAllowsAnyHTTPSCertificate:YES forHost:[myWebserverURL host]];
	NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myWebserverURL]; 
	
	[request addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://heyWorld.org/HelloWorld" forHTTPHeaderField:@"SOAPAction"];//this is default tempuri.org, I changed mine in the project
	
	NSString *contentLengthStr = [NSString stringWithFormat:@"%d", [sRequest length]];
	
	[request addValue:contentLengthStr forHTTPHeaderField:@"Content-Length"];
    // Set the action to Post
    [request setHTTPMethod:@"POST"];
    // Set the body
    [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
    // Create the connection
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	NSMutableData *myMutableData;
    // Check the connection object
    if(conn)
    {
		myMutableData=[[NSMutableData data] retain];
    }
    // Make this class the delegate so that the other connection events fire here.
    [NSURLConnection connectionWithRequest:request delegate:self];
	
    NSError *WSerror;
    NSURLResponse *WSresponse;
    // Execute the asp.net Service and return the data in an NSMutableData object
    myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror]; 
	
	//convert the mutabledata to an nsstring so I can see it with the debugger
	NSString *theXml = [[NSString alloc]initWithBytes:[myMutableData mutableBytes] length:[myMutableData length] encoding:NSUTF8StringEncoding];
Be sure to replace <my host> and <my project> where appropriate (and anything else I have up there that's <my *>), and make sure you are using the namespace you have declared for the service (mine is http://heyWorld.org/ and my function is HelloWorld.)
Credit for the above discoveries and most of the code: Tom McCartan
smthopr8tr is offline   Reply With Quote
Old 01-12-2009, 11:50 PM   #49 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: India
Posts: 223
Default Need help

Hi

I am new in iPhone develpment.

I want to calculate the longitude and latitude of two address using the webservice to calculate the distance between those location.

I dont have any idea, how to use webservice in xcode.

Please help me and if you have any code/link please send it to me.

Thanks in advance.
milanjansari is offline   Reply With Quote
Old 02-20-2009, 11:12 AM   #50 (permalink)
New Member
 
Join Date: Feb 2009
Posts: 6
Default

Quote:
Originally Posted by milanjansari View Post
Hi

I am new in iPhone develpment.

I want to calculate the longitude and latitude of two address using the webservice to calculate the distance between those location.

I dont have any idea, how to use webservice in xcode.

Please help me and if you have any code/link please send it to me.

Thanks in advance.

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
habdelra 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 23,873
Threads: 38,649
Posts: 169,646
Top Poster: smasher (2,547)
Welcome to our newest member, JBTech
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:26 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0