Thursday, April 7, 2011

File URI invalid for WCF HTTP Endpoint

System.ArgumentException: The provided URI scheme 'file' is invalid; expected 'http'.

disconnectedThe error occurred when debugging a Silverlight app that uses Windows Communication Foundation (WCF). When running the debugger, the IDE was launching the html file hosting the Silverlight application, but it was launching it in the browser using a file path, F:\Projects\MyLOBApp\Bin\Debug\TestPage.html, not through IIS as http://localhost/MyLOBApp/TestPage.html. The application was using the following code in a global application class to set the URL to the WCF service.

public static string WebServiceUrlPath
{
    get
    {
        Uri uri = new Uri(Application.Current.Host.Source, "../AppDataService.svc");
        return uri.AbsolutePath.ToString(); 
    }
} 

My solution consists of two projects:


  1. The Silverlight application project
  2. The WCF service project

Upon closer inspection of the file path, Visual Studio was launching the test page from the Silverlight project when it should have been launching the test html page from the WCF project. The simple solution was to set the WCF project as the StartUp Project. That should have been more obvious especially in light of the following message box that popped up before the debugger started, but it was initially overlooked because of the similar project names and html page filenames in the two projects.


image


photo credit: satemkemet / CC BY-SA 2.0

No comments: