MonoTouch, WCF, Large XML response, how to capture progress - wcf

I'm developing an app using MonoTouch and have to get some data from a 3rd party web service. I have a WCF binding to do such.
The particular web service method I am calling could potentially return an XML string in the range of several hundred megabytes, which could take a while to download to a mobile device.
I'm looking for some way to capture how many bytes have been read from the network at the system level, with the end-game being to display a progress indicator to the user. Is there some way I can achieve this using Behaviors?
Note, I don't have any way to modify the web service code to return a Stream object, which is what most of the articles I have found require doing.
Any help or direction would be much appreciated. Thanks
As a last resort, I can always fall back on using an NSURLConnection to do this, instead of WCF, because I know there are NSURLConnectionDelegate methods to hook into that will provide this. I wanted to avoid NSURLConnection, so that I will be able to easily drop this code into an Android project in the future.

Is there a reason to use WCF instead of the plain HttpWebRequest?
WCF is not exactly efficient at parsing data, it will keep multiple copies in memory to deserialize the various chunks of information.
There is no system level API that can provide this information, the Stream that you get back from the HttpWebRequest is the best value that you will get.

Related

WCF - quick response with status then continue doing longer process

I spent few days search on this case. I checked out all wcf asynchronous implementaions.
I wasn't able to find what I was looking for.
Below is scenario.
WCF is running to accept xml
WCF needs to response to user for success receiving xml and release
the request immediately
WCF then needs to do processing to save xml to database and parsing xml to
convert something else.
I don't want to use separate service to process above. I want to use one service to handle all 3 cases above.
I checked out asynchronous way of coding in WCF, but this doesn't release the request right away. What is the best practice for this? Is there any sample code I can use?
Thank you in advance.
I think you would be better suited to using a different technology. Maybe look at Windows Workflow Foundation.
You can host WCF Workflow Services the same way as you host a standard WCF service, the main difference is that you can create specific workflows that can continue after acknowledging receipt of the original message.
You do this by persisting the message and returning to the user. WF allows you to create actions that continue after sending response back to the caller.
Visual studio provides you with a design surface that allows you to drag and drop components to create custom workflows. Additionally you can also make calls to other services if required.
With .net 4.5 you can now use C#, in previous versions of WF you had to use VB.net.
You can read about it on the MSDN site here:
http://msdn.microsoft.com/en-us/vstudio/jj684582.aspx
Hope this helps

How to handle large data from wcf service

I have wcf service, in one of method which returns a list. Getting the data from oracle database, which is a large data(records in lakhs). This method when tested with wcf client works fine. When I consume the same service in silverlight application, I am getting timeout exceptions.. Pls suggest necessary steps to handle large data or avoid this issue.
An application I worked on a few years ago had similar requirements. If my memory serves me correctly, we created some custom WCF behaviours that compressed/decompressed the dataset and transported it as binary data. You could also stream the data but this is a little more brittle in my opinion and requires more work on the client. HTH.
You can do it by holding data in object collection and use silverlight datagrid pagination, so with proper coding you can show atleast 1000 records at time because as per my view user could not look lakhs of records by scroll down and scroll up.
If u don't want pagination then do the background threading, when user scroll up or scroll down data fetch as per index. Handle as much as data in coding level.
Above same thing i have done in my last project.

WCF web service and DynamoDB scaling/performance issue with SDK database object

I am new to creating .NET restful web services and need to grasp the best practices for performance and scaling the following.
I am conncecting to Amazon AWS DynamoDB using their .NET SDK wrapper in C#. My code creates an object that stores the credentials necessary to interface with DynamoDB. What concerns me is that this calls is instantiated on every call. The credentials are stored in my profiles.settings collection and never change.
What I am wondering is whether there is a better way to get these values and create the object once and somehow persist it. I do not know whether or not it is better for performance and scalability to create each time or to look for some type of application cache simulation/alternative that applies to WCF web services.
I also do not know whether static objects come into play here or whether I should steer clear of them.
Any advice would be greatly appreciated.
Thanks!
You could use a static object to persist your credentials considering that those credentials are stored in your config file and as you have mentioned they do not change. Related to the WCF REST aspect, you could really simply your life by using WebAPI the new REST "framework" from Microsoft. WCF is kind of clumsy when it comes to REST.

WCF IAsync or other Way to Show Progress on Client?

I have a simple console app that calls a WCF service over net.tcp and uploads a file (using Stream). The WCF service is self-hosted, Framework 4.0.
I am looking for a way to now add some "progress info" on the client-side. Should this be done with hand-written IASync operations, or something else altogether?
This is actually pretty easy, though the solution doesn't really have anything to do with WCF. Create a wrapper Stream subclass that you pass the actual source Stream into. In the various Read overrides, first delegate to the underlying Stream you're wrapping. Next, increment a custom property with the number of bytes read and either fire a custom event or maybe implement INotifyPropertyChanged on the custom Stream subclass. By doing this, as WCF reads from the wrapper Stream to get the bytes to send over the wire, your client will be able to observe the changes.

WCF System.ServiceModel.Channel.Message: binary message contents (non-XML)?

I need to retrieve binary (non-XML) documents as Messages in a custom WCF LOB Adapter (for consumption by BizTalk). The messages need to be represented as instances of System.ServiceModel.Channel.Message.
I can't find how to create an instance of this class when the content is binary (by "binary" I mean any arbitrary byte array or Stream, and not only binary representations of XML documents).
Is this possible? Or would wraping the binary contents in an XML enveloppe be the only way to do this in WCF?
Fundamentally, WCF messages are XML, since the S.S.C.Message class uses the Xml InfoSet as the base message representation.
So yes, in some way you need to "wrap" your binary content into an XML envelope (which doesn't need to be a SOAP envelope, mind you, depending on how your binding is configured).
That said, note that this doesn't preclude streaming to deal with large message payloads without buffering the entire message in memory; WCF still allows you to do this, though sometimes it's not greatly obvious how it works.
Since you're working with a custom channel, you've got one of two choices, I think:
Have your own channel add the XML wrapper around your binary content before passing it upwards or
Create a custom MessageEncoder that adds it in for you automatically.
In either case, if you're dealing with large messages, you'll want to make sure you use the MessageEncoder overloads that handle Streams instead of buffers, as they are the ones that give you the option of doing coordinated streaming with the service implementation.
WCF offers some ways to send binary attachments and stream data in various ways. We have an application at work that does this, but I haven't had a chance to dig through the code, so I can't offer too much help. Here are a few links that might get you started (Nicholas Allen's Indigo Blog is a great place for WCF info):
http://blogs.msdn.com/drnick/archive/2006/03/31/565558.aspx
http://weblogs.asp.net/cibrax/archive/2007/08/29/sending-attachments-with-wcf.aspx