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.