posting image from iphone app to restful WCF - iphone

I need to post image from ios app to .net 4 restful WCF service. Can someone help with following codes together (as a working package),
on .NET side: Interface code, Service code (implemenation) and web.config XML.
on IOS side: the posing to the wcf part.
although there seem to be several sources online about how to achieve this, after long time messing with it, still can't get it going.
Thanks a lot!

For the server side: take the input as a Stream - that way you can receive arbitrary data (including images). More information in this blog post. For the client side: take a look at the NSURLRequest class - if you search for examples, you'll find many, including here from StackOverflow.

Just send the image as byte array to the wcf service and store it as blob in SQL server if you need to store.

Related

RESTful web server library for iOS

I am trying to create a Rest web service running on iPhone; I've done my initial research and found
CocoaHttpServer and TouchCode json parser, is there any library / sample code which binds these together into a Rest endpoint?
If it does not exist, how do I go about writing one? Any reference to some kind of design document etc. will really help.
I'm using CocoaHTTPServer and the iOS builtin JSON libraray to have a RESTful service in iVocabulary. First I wrote a lengthy Connection class (the core for handling requests in CocoaHTTPServer) myself. But parsing the URL was kind of complicated.
So I wrote a more generic Connection class that routes HTTP requests to different blocks for different URLs and different HTTP methods. The URL can contain parameters (with : as prefix), that get parsed. That's not a generic REST service per se, but I added (for example) a block for the url "/rest/:entityname" that fetches all Core Data objects of the given entity.
You can find that router implementation in my fork of CocoaHTTPServer on github: https://github.com/chbeer/CocoaHTTPServer
Another router implementation: https://github.com/mattstevens/RoutingHTTPServer
Check RestKit for working with Restful web services.
http://restkit.org/
I recommend RestKit, I have used for over a year now and love it. However I recently learned about AFNetworking from some colleagues that claim it's very lightweight and thus prefer it as an alternative to RestKit, so I am giving it a try soon.

Dealing with WCF in iPhone/iPad project

I'm trying to make my Monotouch app work with WCF service. Everything works fine but every now and then (10 - 30 service calls), app crashes with SIGIL. Debugger says just that.
It happens on random places.
Another employee works on iPhone app which uses same service. Same problem, but more frequent.
Everything works great when testing on simulator.
If somebody's had same problem, please help. Would using asmx service help?
Thank you all.
Cheers
WCF is a bloated option on high traffic servers at the best of days, using SOAP in a mobile application is a enough of a waste of resources that it should be considered bad practice.
ServiceStack is a much leaner and faster option that also allows you to access your same web services with ServiceStack's strong-typed, code-gen-free Service Client's using .NET's fastest JSON and JSV Text serializers.
The MonoTouch versions of ServiceStack's service clients is available separately from:
https://github.com/ServiceStack/ServiceStack/tree/master/release/latest/MonoTouch
And an example MonoTouch application that showing how to use is available here:
https://github.com/ServiceStack/ServiceStack.Examples/tree/master/src/MonoTouch/RestFilesClient
Not much an answer, but I had a similar issue. Worked for a long time to get my desktop WCF client code running on MonoTouch, only to have the app die after 10 or so calls on SIGIL.
Symbolicating and analysing the crash reports showed the app dying somewhere in the WCF stack every time. However I could not distill the issue down into a trivial, reproducable example.
In the end I used the ServiceStack framework (http://www.servicestack.net/) to throw a simple XML REST endpoint in front of my service, and called it using simple WebClient requests and some helper methods to push my objects to/from XML (DataContractSerializer was too slow).
If you have access to the server side, this may be your simplest approach.

Converting SOAP to REST?

I have a web app, that also has an iPhone and Android app using the same API. It hasn't yet been made publicly available, so I wanted to look to convert from SOAP to REST.
I was only able to find a few tutorials that go into thorough explanations of how to code a REST web service, and of those I only found the MSDN one useful. The problem is I got really confused when they started using URI data types inside the object.
My question is, if you are converting SOAP to REST, do you have to recreate all the objects to add the URI? Am I not able to just have a REST entry point, then call one of the classes that retrieve the data?
Once the REST service is made it will only be used by my mobile apps, but not the website (since that can directly access the classes), which makes me not want to change the objects to add a URI. Is that a correct assumption to make, or should the web services also be called by the website?
Sorry if these are newbie questions, but I am struggling to get my head around REST, and I haven't had much experience creating the architecture of potentially high user base apps.
If anyone is able to point me to an actual code set, that would be helpful.
Edit: I am using VS2010, coding in C# and .Net 4.
Thanks a lot,
Andy
Im doing a very similar thing right now :). Rest via wcf isnt too hard, you do have to sometimes add your endpoints in the web config and give it the [webget]/[webinvoce] attributes in the refrence.cs of the web refrence when consuming though c# which is annoying.
Here is a code set i used when getting started. There are a few more on code project too.

How to start use webservice

i want to read and write data to a website (server on web) and don't have any information about webservices and other things that related to it
Does anybody have any idea about how to start it (mean offer complete books,papers,tutorials,websites,… or what should i learn at first mean is it necessary to learn xml,soap,... and other things)
Thank you
I've used Google App Engine with great success. You would format your data to output as JSON and use an iPhone library to read it. I've used this one (though Touch JSON seems to be more popular).
Read about REST, ROA and AtomPub. Thats got me started. I'm about to implement some webservices in WCF (WCF now acts like a RESTFul webservice, but you can also use plain old SOAP). Before I got to WCF, I experimented with RoR. RoR uses REST "out-of-the-box".

Access sharepoint web services in iphone app

I am trying to access sharepoint default web services from my iPhone app. Can some one help me with how to construct the request and get the proper response.
Thanks,
Naresh
Your question can really only be answered in two parts. Part one is how to construct a request to any web service...which is what the answer at Consume WCF Web Service using Objective-C on iPhone will show you.
The second part is SharePoint related - their web services requires you to construct chunks of XML that are passed as parameters, and the XML you pass in is in a format that Microsoft specifies. For example, Lists.UpdateList method (at http://msdn.microsoft.com/en-us/library/lists.lists.updatelist ) requires 6 parameters, 4 of which are XML fragments -- which will need to be encoded and escaped. (SharePoint's web services are difficult to deal with on any platform and I would expect it to be doubly so from iPhone).
See here for answer..
Consume WCF Web Service using Objective-C on iPhone