How do I use code generated from WSDL2OBJC - iphone

hi everyone i am new to iphone development and started with some sample application.
In sample application i am using webservices..i went through this tutorial http://code.google.com/p/wsdl2objc/wiki/UsageInstructions and understood about wsdl2objc..
but this tutorial is too short so can anyone suggest similar like tutorial or examples so tat is still more clear...
thank u

All depends on your web service class name etc as wsdl2objc makes up alot of your NSObjects and methods based upon this, however,
suggesting that you are using soap 1.2 bindings and your web service was called 'SimpleService', the following would call a web method named 'MobileTestService and return back the integer value from the xml generated.
-(NSString *)returnThatStringFromWebServiceResult {
SimpleServiceSoap12Binding * binding = [SimpleService SimpleServiceSoap12Binding];
binding.logXMLInOut = YES; // shows all in the console log.
SimpleService_concat * testParams = [[SimpleService_concat new]autorelease];
testParams.s1 = someTextField.text; // parameters all become properties of this testParams object
testParams.s2 = anotherTextField.text;
SimpleServiceSoap12BindingResponse * response= [binding SimpleService_concatUsingParameters:testParams];
[response self]; // removes compile error
NSArray * responseBodyParts = response.bodyParts;
NSError * responseError = response.error;
if (responseError!=NULL) {
return #""; // if error from ws use [responeError code]; for http err code
}
for (id bodyPart in responseBodyParts)
{
if ([bodyPart isKindOfClass:[SimpleService_concat_Response class]])
{
SimpleService_concatResponse* body = (SimpleService_concatResponse*) bodyPart;
return body.SimpleService_concatResult; // if you are returning a string from your WS then this value will be a string,
}
}
}

Related

Get host server name through email address in mail core2 framework for iOS

I want to know the default host name through the name of the email address....
I found a method in a class "MCONetService.h"....
hostnameWithEmail:
the reference link..
http://libmailcore.com/mailcore2/api/Classes/MCONetService.html
...but my problem is that i am unable to find the proper way to use this method because it is an instance method which requires the "MCONetService" class object to call that method,and i am getting null because it seems this object need some value before the use...
my code ...
MCONetService *netService=[[MCONetService alloc]init];
[netService hostnameWithEmail:#"email#gmail.com"];
This is not a good way of coding but did't found any other way to try this method...
Any help will be appreciable....
Here's how to do it:
First, make sure that you include providers.json in the resources of your app.
Here's how to get the IMAP server related to a given email address.
NSString * email = #"email#gmail.com";
MCOMailProvider * provider = [[MCOMailProvidersManager sharedManager]
providerForEmail:email];
NSString * hostname = nil;
if ([[provider imapServices] count] > 0) {
MCONetService * service = [[provider imapServices] objectAtIndex:0];
hostname = [service hostnameWithEmail:email];
}
if (hostname == nil) {
NSLog(#"no IMAP server found");
}
else {
NSLog(#"IMAP server: %#", hostname);
}

Accessing GTLPlusActivity properties

I have integrated the Google Plus iOS SDK v1.2.1 into my iOS app. After authentication I am trying to fetch the user's activity feed. My code is the following:
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
[plusService setAuthorizer:[GPPSignIn sharedInstance].authentication];
plusService.retryEnabled = YES;
GTLQueryPlus *query = [GTLQueryPlus queryForActivitiesListWithUserId:#"me" collection:kGTLPlusCollectionPublic];
[plusService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLPlusActivityFeed *data,
NSError *error) {
for (GTLPlusActivity *activity in data.items) {
// ITERATE THROUGH THE ACTIVITIES
NSString *publishedDate = activity.published; <---- ERROR
// "PROPERTY 'published' CANNOT BE FOUND
// IN FORWARD CLASS OBJECT "GTLPLusActivity""
// WHY ARE THE VARIABLES SUCH AS published, placeName,
// title, actor etc NOT ACCESSIBLE
}
}];
I am able to successfully retrieve the posts of the user. The GTLPlusActivity class has many properties as shown in the image:
Whenever I try to access the properties using the "." operator such as "activity.actor" in the for loop, it gives the error "Property 'actor' cannot be found in forward class object 'GTLPlusActivity'". Why am I unable to access the properties? I need to display them in a UITableView.
EDIT: Code Snapshot. Error clearly displayed in Red.
Firstly, check the error condition and make sure the error code is nil. I have tried your code, and it works correctly on my end, so most likely, there is a problem with the response you are getting back. Generally activity.actor will return a GTLPlusActivityActor.
Try something like:
if (error) {
NSLog(#"Status: Error: %#", error);
}
else
<Do stuff>
EDIT: Also, our iOS quick-start is a great resource for seeing how we handle certain parts of the code. The ListMoments bit is pretty similar to dealing with Activities.
https://developers.google.com/+/quickstart/ios
EDIT 2: Also, make sure you have all of the right imports. Try
#import "GTLPlusActivity.h"
or
#import "GTLPlus.h"

Sudzc iPhone SOAP - How can I handle a SOAP fault using this library auto-generated data?

I have a response, which returns SOAP fault in case of exception. I want to handle this SOAP Fault. But, the response I get by deserializing the SOAP response does not have a SOAP Fault.
I have used Sudzc Library to generate the objective C code for my web services.
Help will be appreciated.
Thanks,
Priya
There seems to be a bug in the SoapRequest.m that is bundled with Sudzc.
Specifically, if you take a look at the
- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
method and navigate to the following bit of code:
id output = nil;
SoapFault* fault = [SoapFault faultWithXMLDocument: doc];
if([fault hasFault]) {
if(self.action == nil) {
[self handleFault: fault];
} else {
if(self.handler != nil && [self.handler respondsToSelector: self.action]) {
[self.handler performSelector: self.action withObject: output];
} else {
NSLog(#"SOAP Fault: %#", fault);
}
}
}
You can see that output will always be nil when returned to the handler.
To fix this issue, you can simply return the SoapFault instead of the output to your handler like so:
...
[self.handler performSelector: self.action withObject: fault];
...
In your Sudzc return Handler Method, you can [idOfSoapObject isKindOfClass:[SoapFault class]]
If you are already doing this, then I would suggest turning Logging on: your service will have a .logging(BOOL) property. This will log the full soap requests and responses. Here you can check the response manually for a fault.

How to use Three20 framework to upload multiple images and handle JSON response?

So I have an iPhone application that needs to:
Post several strings and up to 5 images (stored in memory) to a RoR web application
Parse the JSON returned that will include several strings and an array of URLs (each representing the location of where the uploaded images can be found on the website).
QUESTIONS:
Can this be done with Three20 (would be nice since I'm using it for other things)? And if so, how?
If it can't be done with Three20 ... how would it be accomplished using ASIHttpRequest? Or maybe something baked into the SDK if that is a better option?
Thanks much
Unfortunately there isn't a whole lot of tutorials and good documentation for three20 out there on the web ... so here is how I finally got things working:
- (void) sendToWebsite {
NSString* url = [[NSString stringWithFormat:kRequestURLPath, self.entityId] stringByAppendingString:#".json"] ;
// Prep. the request
TTURLRequest* request = [TTURLRequest requestWithURL: url delegate: self];
request.httpMethod = #"POST";
request.cachePolicy = TTURLRequestCachePolicyNoCache;
// Response will be JSON ... BUT WHY DO I NEED TO DO THIS HERE???
request.response = [[[TTURLJSONResponse alloc] init] autorelease];
// Set a header value
[request setValue:[[UIDevice currentDevice] uniqueIdentifier] forHTTPHeaderField:#"Device-UID"];
// Post a string
[request.parameters setObject:self.entity_title forKey:#"entity_title"];
// Post some images
for (int i = 0; i < [self.photos count]; i++) {
// IS IT POSSIBLE TO ADD A PARAM NAME SO I CAN LOOK FOR THE SAME NAME
// IN THE WEB APPLICATION REGARDLESS OF FILENAME???
[request addFile:UIImagePNGRepresentation([self.winnerImages objectAtIndex:i])
mimeType:#"image/png"
fileName:[NSString stringWithFormat:#"photo_%i.png", i]];
}
// You rails guys will know what this is for
[request.parameters setObject:#"put" forKey:#"_method"];
// Send the request
[request sendSynchronously];
}
Things I still don't understand (or find problematic):
For a posted file, how can I include both a param name AND a filename?
What is the purpose of setting request.response = to whatever? I don't get that.
Answering #2:
You need to supply the handler for the response before you send your request, the TTURLJSONResponse is not the actual response, but it's responsible for handling the response. This is where you'd process the response for your strings and array of URLs.
It's really a protocol called TTURLResponse that defines the following method for implementation:
/**
* Processes the data from a successful request and determines if it is valid.
*
* If the data is not valid, return an error. The data will not be cached if there is an error.
*
* #param request The request this response is bound to.
* #param response The response object, useful for getting the status code.
* #param data The data received from the TTURLRequest.
* #return NSError if there was an error parsing the data. nil otherwise.
*
* #required
*/
- (NSError*)request:(TTURLRequest*)request
processResponse:(NSHTTPURLResponse*)response
data:(id)data;
You chose TTURLJSONResponse as your handler, which is a straight-forward implementation to look at for help on writing your own.

iphone programmatically read proxy settings

I'm looking at adding proxy support to my iphone svn client. When you set up a system wide vpn in the iphone settings you can add a global proxy. Is it possible for external apps to read this information through the api?
Apple has created a sample application for this purpose, called CFProxySupportTool.
CFProxySupportTool shows how to use the CFProxySupport APIs to determine whether a network connection should pass through a proxy; this is useful if you're not using Apple's high-level networking APIs (like CFNetwork and the Foundation URL loading system) but still want to interpret the system-supplied proxy settings.
It's currently available at
https://developer.apple.com/library/mac/#samplecode/CFProxySupportTool/Introduction/Intro.html
The code isn't exactly terse (more than 1000 lines), and is written in plain C. You can also look at the source code of ASIHTTPRequest's startRequest function, which seems to be based on CFProxySupportTool.
Here's a start:
systemProxySettings = [(NSDictionary *) CFNetworkCopySystemProxySettings() autorelease];
proxies = [(NSArray *) CFNetworkCopyProxiesForURL((CFURLRef) URL, (CFDictionaryRef) systemProxySettings) autorelease];
if (!proxies.count)
return;
firstProxySettings = [proxies objectAtIndex:0];
if (nil != (pacScriptURL = [firstProxySettings objectForKey:(NSString *)kCFProxyAutoConfigurationURLKey]))
{
CFErrorRef cfErrorRef = NULL;
NSError *nsError = nil;
NSString *script;
script = [NSString stringWithContentsOfURL:pacScriptURL
usedEncoding:NULL
error:&nsError];
if (nsError)
return;
proxies = [(NSArray *) CFNetworkCopyProxiesForAutoConfigurationScript((CFStringRef) script, (CFURLRef) URL, &cfErrorRef) autorelease];
if (cfErrorRef || !proxies.count)
return;
firstProxySettings = [proxies objectAtIndex:0];
}
/* Now use `firstProxySettings' */
A Swift 4 version (special thanks to mortehu for providing the initial example).
//Shown this way for clarity, you may not want to waste cycles in your production code
if let url = URL(string: "https://someurloutthere.com") {
let systemProxySettings = CFNetworkCopySystemProxySettings()?.takeUnretainedValue() ?? [:] as CFDictionary
let proxiesForTargetUrl = CFNetworkCopyProxiesForURL(url as CFURL, systemProxySettings).takeUnretainedValue() as? [[AnyHashable: Any]] ?? []
for proxy in proxiesForTargetUrl {
print("Proxy: \(String(describing: proxy))")
//Print the proxy type
print("Proxy Type: \(String(describing: proxy[kCFProxyTypeKey]))")
//There different proxy value keys depending on the type, this is an example of getting the proxy config script if the type is kCFProxyTypeAutoConfigurationURL. If the proxy type were kCFProxyTypeSOCKS you would want to access the SOCKS property keys to see/get the SOCKS proxy values
print("Proxy Autoconfig script URL: \(String(describing: proxy[kCFProxyAutoConfigurationURLKey]))"
}
}
Have you investigated using something like ASIHttpRequest, see the section in the how to document describing proxy support.
At the very least the source code should contain some helpful guidance.
Take a look at the CFProxySupport API, in particular CFNetworkCopyProxiesForURL() will let you read the proxies that are needed to get to a particular URL.