Rich Web client development with ASP.NET ,LINQ , WCF and now Silverlight2

Wednesday, January 28, 2009

exception debugging in silverlight

the invaluable tool in cases where wcf methods are throwing on a web site is Web Developer helper or fiddler. if an exception is thrown WCF does not send much info on the wire even when one enables

I recently was trying to return a hunk of XML in my WCF service and was mystified as to why my method was failing till I looked at the response Content in Developer helper's log Viewer. Then the problem was visible:


a:DeserializationFailedThe formatter threw an exception while trying to deserialize the message: Error in deserializing body of request message for operation 'SaveContactsXML'. The maximum string content length quota (8192) has been exceeded while reading XML data. This quota may be increased by changing the MaxStringContentLength property on the XmlDictionaryReaderQuotas

Saturday, January 10, 2009

getting root path in Silverlight WCF method

I have been playing with my Outlook like scheduler lately and added the capability to import contacts from Outlook itself. I just output a CSV file from Outlook and then convert the CSV file into an XML and a data base table (for a future version). I then wrote a WCF method to download and another to upload the file as I wanted the user of my Contact view to be able to edit the contents. I
copied the contacts XML file to a Contacts folder in my ClientBin directory (IIS Virtual)
My simple interface looks like:

public interface ISchedulerServices
{
[OperationContract]
string GetContactsXML(string use);
[OperationContract]
void SaveContactsXML(string newXML);
}

of course both of these methods need to know the location of the XML file that contains the contacts. I had to find a way to access the HTTP context from the implementation of these methods as my service is IIS hosted. I accomplished this by adding the following decoration to my implementation:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

and to the web.config:



this I inserted right after the behaviors section so the looks like:

<system.servicemodel>
<behaviors>
<servicebehaviors>
<behavior name="SchedulerV4.Web.SchedulerServicesBehavior">
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="true">
</behavior>
</servicebehaviors>
</behaviors>
<servicehostingenvironment aspnetcompatibilityenabled="true">
<services>

<service behaviorConfiguration="SchedulerV4.Web.SchedulerServicesBehavior>

NOTE: I realize that there is a project option called Siverlight enabled WCF service but I had problems with the code it produced and these steps are pretty easy.

Now I could get the path with the following code:

string root = HttpContext.Current.Server.MapPath("~/");
strFilePath = root + "clientbin/contacts/johncontacts.xml";

Then I was largely in business except for an exception that was thrown when I called the Save method . This threw an exception as my XML was larger tha 8192 btyes however the exception gave me no clue to the issue. However WebDevHelper to the rescue as the real error was buried in the Response Content.

NOTE: I should mention that I was unable to add this WCF method using Vista 64 as Visual Studio crashes. To solve the problem I had to reinstall the Siverlight Toolkit for SP1.

Friday, January 09, 2009

Rich UI business example with Silverlight

For a great example of what one can do with Silverlight to produce a truly desktop like business application check out Zignals at http://www.zignals.com/main/charts/trystockcharts.aspx.
Wow!