CSLA Light - FileInfo

CSLA Light - FileInfo

Old forum URL: forums.lhotka.net/forums/t/7030.aspx


CampbellCM posted on Monday, June 01, 2009

Can anyone think of a way to get a FileInfo object from the SL client to the WCF server via CSLA?

sergeyb replied on Monday, June 01, 2009

Not quite sure what you are asking. OpenDialog in SL returns a stream that you can save in byte[] property of your object and send it that way to the server. The only caution would be the size. For larger files you would be better off using WCF streaming.

Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899

Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

-----Original Message-----
From: CampbellCM [mailto:cslanet@lhotka.net]
Sent: Monday, June 01, 2009 5:32 PM
To: Sergey Barskiy
Subject: [CSLA .NET] CSLA Light - FileInfo

Can anyone think of a way to get a FileInfo object from the SL client to the WCF server via CSLA?

CampbellCM replied on Tuesday, June 02, 2009

Yeah, my problem is that the files are large, multi-MB.  I tried passing the contents as a string (it's a text file) but the serializer choked big time (yes, I'm using compression).  The easiest thing would be to pass the file name from the FileInfo object from the client to the server but that kind of information is off limits in the SL runtime.  The next easiest thing would be to pass the entire FileInfo object because the file name and such would be accessible once the object got to the server.  That's not possible either because the FileInfo class is not serializable.  So then I tried serializing the file contents via the CSLA serializer and some part thereof or below choked on it.  I spent the rest of today trying to get WCF streaming to work and had no luck there either.  It seems like anything worth serializing is not serializable.

Sergey, I don't suppose you recall seeing an example of WCF Streaming...

RockfordLhotka replied on Tuesday, June 02, 2009

A quick bing search on uploading files from Silverlight reveals many answers, including a pre-built solution on codeplex: http://www.codeplex.com/SilverlightFileUpld

CampbellCM replied on Thursday, June 04, 2009

Thanks Rocky, but uploading a file is not quite what I'm after. I need to be able to send the contents of a file from the client to the server so that said contents can be processed on the server. I am using a CommandBase derived class to do that.

In any case, I have discovered what the problem was...why getting the data from the client to the server was failing. It turned out to be a missing configuration setting in my Web.config file:

[system.web]
[httpRuntime maxRequestLength="2097151"/]
[/system.web]

The maxRequestLength parameter tells the web service how large a request from the client can be and without it requests are limited to somewhere between 10KB and 20KB. As soon as I added that parameter/value it just started to work, no problems.

For the sake of others that may read this I would like to add that I am using compression as recommended and I am also including the relevent contents of my server-side Web.config file and my client-side ServiceReferences.ClientConfig file.

Web.config:

[system.serviceModel]
[behaviors]
[serviceBehaviors]
[behavior name="WcfPortalBehavior"]
[serviceMetadata httpGetEnabled="true"/]
[serviceDebug includeExceptionDetailInFaults="false"/]
[/behavior]
[/serviceBehaviors]
[/behaviors]
[services]
[service behaviorConfiguration="WcfPortalBehavior" name="Fidelity.Management.Compression.CompressedHost"]
[endpoint address="" binding="basicHttpBinding" contract="Csla.Server.Hosts.Silverlight.IWcfPortal" bindingConfiguration="BasicHttpBinding_IWcfPortal"/]
[/service]
[/services]
[bindings]
[basicHttpBinding]
[binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"
receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"]
[readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647"/]
[/binding]
[/basicHttpBinding]
[/bindings]
[/system.serviceModel]

ServiceReferences.ClientConfig:

[configuration]
[system.serviceModel]
[bindings]
[basicHttpBinding]
[binding name="BasicHttpBinding_IWcfPortal" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"
receiveTimeout="00:10:00" sendTimeout="00:10:00" openTimeout="00:10:00" closeTimeout="00:10:00"/]
[/basicHttpBinding]
[/bindings]
[client]
[endpoint address="http://localhost:2978/CompressedWcfPortal.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IWcfPortal" contract="Csla.WcfPortal.IWcfPortal" name="BasicHttpBinding_IWcfPortal"/]
[/client]
[/system.serviceModel]
[/configuration]

In order to post this information I had to replace all of the less than and greater than characters with left and right square bracket characters.

I would also like to emphasize the importance of accuracy in these files. If things are not working as expected it may just be because of a typo in either or both files (I should know!).

Perhaps some of this information could be added to the CSLA Light FAQ.

Copyright (c) Marimer LLC