Consuming ASP.NET(Asmx) web service (Cocoa/Objective-C) - objective-c

I have ASP.NET webservice(Asmx) which I need to consume in Cocoa/Objective-C. What is the simplest/optimal way to achieve this? I have done the implementation where we have many delegates for XMLParser and connection. like didStartElement, didEndElement....
Is there any other way to achieve this? In .NET I have done a similar implementation where I have a proxy class and when I make a call to the web method I get a response which is the return value of the web method rather than parsing the response xml.
Please let me know.

Try out some of the existing network frameworks before writing your own (RESTKit, AFNetworking, etc.) - They all have good tutorials on how to easily consume webservices.
A little bit off-topic, but it seems that your Webservice returns a XML response. I would (but that's just me!) try to change that to JSON. Cocoa/Obj-C provides built-in functions to deserialize JSONs, and the aforementioned frameworks also work quite well with this format. It's far easier to use than NSXMLParser etc.

Related

Objective-C Sudzc WSDL Generator Alternative

Sudzc (www.sudcz.com) appears that it is no longer a project that is being contributed to!
After a year of no commits and some serious bugs especially with returning list of objects this helpful tool appears to be fading into the black holes of the internet.
I was wondering if anyone knew of an alternative tool that works the same way as this?
Or are soap requests no longer a preferred method of data transfer? Is json a better approach using rest clients?
Bonus question: Is there a way to make sudzc handle a returned list of objects
Some alternatives are:
Easy WSDL
Wsdl2Code
This answer mentions another alternative, wsdl2objc.
Within the generated SoapRequest.m file there you can find the implementation of
- (void) connectionDidFinishLoading:(NSURLConnection *) connection
Look for
if([deserializeTo respondsToSelector: #selector(initWithNode:)])
{
element = [element childAtIndex:0];
output = [deserializeTo initWithNode: element];
}
and remove the line with "element = [...]". If you do so keep in mind that you could have to do fixes in other parts of your generated .m files because of this change. This depends heavily on your WebService layout. Hope this helps.

Profiler lib for wcf + postsharp

We need to add a new profiling feature to our WCF application, for logging where time is spendt in the application. I'm looking at PostSharp for a convention driven approach of applying the logging and need some input on how to actually log it. I've already created a custom class for logging purposes, using StopWatch and can log the steps through the layers of my WCF application. However I'm wondering if there's a thread safe alternative library I could use in conjunction with PostSharp for this purpose. I've come across MiniProfiler, but it seems to be intended for ASP.NET MVC applications mainly. Any other frameworks I should consider or should I just use my custom class?
Thanks
I did something like that in the past using a IClientMessageInspector implemented on a custom IEndpointBehavior.
Depending on what kind of logging you want, this might just do the trick. There's an example in the following link
IClientMessageInspector Interface
PostSharp itself is thread-safe. The aspects that you write may be thread-unsafe if poorly written, but there's always a way to make them thread-safe.
If you're using OnMethodBoundaryAspect and need to pass something from OnEntry to OnSuccess, store the initial stopwatch value in OnMethodExecutionArgs.MethodExecutionTag.

Parsing the Xml data in xcode

I am beginner to iphone. My requirement is to invoke the sap webservice in iphone.I got the result data which is in xml form.The result is to be in NSString which is of Xml form.Then how to get that result into the array in xcode.Please help me.
Here is a great library on GitHub-XML to NSDictionary
It isn't quite an NSArray but xml files are rarely just Arrays, so this provides an intermediate, dictionaries when needed, arrays if possible.
1. You can use NSXMLParser for this purpose, read through the delegate methods in https://developer.apple.com/library/ios/documentation/cocoa/reference/NSXMLParserDelegate_Protocol/Reference/Reference.html
2. This question is pretty repetitive, you could have just googled "Parsing the Xml data in iPhone" or "Parsing the Xml data using xCode" you would have got loads of results. Go trhough this ->
http://www.xcode-tutorials.com/parsing-xml-files/
and maybe this-> http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/
3. Next time please do search.
Your question is quite general and it's difficult to give you a specific answer.
Here some guidelines to consume web services in iOS.
First, you need to have a mechanism that helps you to consume the ws. To do it, you can use NSUrlConnection class (see NSURLConnection Class) or use a the ASIHttpRequest framework (see ASIHTTPRequest). In this manner you can make requests and dowload response messages.
Since you use soap messages, you have first to create the request message manually. You can use class method of NSString stringWithFormat or use ASIFormDataRequest class of ASIHttpRequest framework.
Finally, if you receive a message that is like the following you posted in your comment, you need to parse it. Remember that is a soap message and it doesn't have only your tags. To do it, you can use NSXMLParser class (see NSXMLParser Class) or use GDataXML parser (see how-to-read-and-write-xml-documents-with-gdataxml).
Out there there are plenty of tutorials or posts on how to "consume web services on iOS". You can find them. In addition, there are also some kits that, taken the your service, create class wrappers to consume your services. In this case you don't need to create or parse manually masseges.
A last remark. When you need to consume data taken from a service, maybe a REST architecture could be easier to set up.
Hope it helps.

Creating an Objective-C API

I have never made an API in objective-c, and need to do this now.
The "idea" is that I build an API which can be implemented into other applications. Much like Flurry, only for other purposes.
When starting the API, an username, password and mode should be entered. The mode should either be LIVE or BETA (I guess this should be an NSString(?)), then afterwards is should be fine with [MyAPI doSomething:withThisObject]; ect.
So to start it [MyAPI username:#"Username" password:#"Password" mode:#"BETA"];
Can anyone help me out with some tutorials and pointer on how to learn this best?
It sounds like what you want to do is build a static library. This is a compiled .a file containing object code that you'll distribute to a client along with a header file containing the interface. This post is a little outdated but has some good starting points. Or, if you don't mind giving away your source code, you could just deliver a collection of source files to your client.
In terms of developing the API itself, it should be very similar to the way you'd design interfaces and implementations of Objective-C objects in your own apps. You'll have a MyAPI class with functions for initialization, destruction, and all the functionality you want. You could also have multiple classes with different functionality if the interface is complex. Because you've capitalized MyAPI in your code snippet, it looks like you want to use it by calling the class rather than an instance of the class - which is a great strategy if you think you'll only ever need one instance. To accomplish this you can use the singleton pattern.
Because you've used a username and password, I imagine your API will interface with the web internally. I've found parsing JSON to be very straightforward in Objective-C - it's easy to send requests and get information from a server.
Personally I would use an enum of unsigned ints rather than a NSString just because it simplifies comparisons and such. So you could do something like:
enum {
MYAPI_MODE_BETA,
MYAPI_MODE_LIVE,
NUM_MYAPI_MODES
};
And then call:
[MyAPI username:#"Username" password:#"Password" mode:MYAPI_MODE_BETA];
Also makes it easy to check if they've supplied a valid mode. (Must be less than NUM_MYAPI_MODES.)
Good luck!

Mocking wcf in silverlight

I thought that I could create a WCF in and call it in Silverlight. I would inject an interface to the WCF. Then in my unit test I would mock the wcf....
However when I actually got to do this I notice that the interface does not actually have the methods that I am calling.
ie
myWCF.myfunctionCompleted(myhandler);
myWCF.myfunctionAsyc("test");
How to people typically accomplish this?
I would create a MyWCFService class which would wrap all the work calling out to my generated WCF proxies.
This helps in a few ways:
Gives you a single point to keep all of the code related to calling WCF (which can be quite a bit with proper error handling).
Gives you a class you can mock out for calling.
Gives you an opening to easily replace WCF if you need/want too by not avoiding WCF specific code being sprinkled everywhere (unlikely but you never know).