Deploying Silverlight / WCF with VS2010

Discussion in 'Site Programming, Development and Design' started by A Hill, Apr 16, 2010.

  1. Hi,

    I'm completely new to ASP & ISS but familiar with C# & Silverlight. Please could someone detail the steps for configuration and deployment for this ultra-basic Silverlight app & WCF Web Service using VS2010 Pro & Winhost?

    I'm looking for "The correct approach" as much as the actual details, although please assume I don't know where anything is in IIS or VS2010.

    Many thanks in advance - I've been wrangling over this for ages now, previously with VS2008. Ideally I want to use VS2010 albeit in .net 3.5 for the time being.

    ---

    1. Create new "Silverlight Application" (.NET Framework 3.5) as "MyWcfExperiment"
    2. Tick "Host the Silverlight application in a new Web site (MyWcfExperiment.Web)
    3. Add a button to MainPage.xaml (conent = "Test .svc")
    4. Add 3 x Textblocks (textBlock1, textBlock2, textBlock3)
    5. Double click button to add click event handler
    6. Right-click MyWcfExperiment.Web in solution explorer, Add->New Item
    7. Select WCF Service (name = "MyWcfService.svc")
    8. Alter void DoWork() to DateTime getTime() in .sc and .svc.cs code bhind file
    9. Add statement "return System.DateTime.Now;" to the code behind file
    10. Save and build projects
    11. Right-click MyWcfExperiment in solution explorer, Add Service Reference
    12. Hit discover
    13. Expand MyWcfService.svc & MyWcfService to reveal IMyWcfService (select it)
    14. Namespace "MyWcfServiceReference" -> Ok
    15. Open MainPage.xaml.cs
    16. Add line "using MyWcfExperiment.MyWcfServiceReference;"
    17. Add the code found below.
    18. Build and run - this will work perfectly as it's local

    What is the "correct" way to deploy and configure this given I'm using VS2010 Pro and a basic Winhost account?
    Longer term I want to make some simple Silverlight GUIs hooking up to SQL Server, but one step at a time. :)


    private void button1_Click(object sender, RoutedEventArgs e)
    {
    MyWcfServiceClient proxy = new MyWcfServiceClient();
    proxy.getTimeCompleted += new EventHandler<getTimeCompletedEventArgs>(proxy_getTimeCompleted);
    proxy.getTimeAsync();
    }

    void proxy_getTimeCompleted(object sender, getTimeCompletedEventArgs e)
    {
    //throw new NotImplementedException();
    try
    {
    textBlock1.Text = e.Result.ToLongTimeString();
    }
    catch
    {
    textBlock1.Text = e.Error.ToString();
    textBlock2.Text = e.Error.Message;
    textBlock3.Text = e.Error.InnerException.Data.ToString();
    }
    }
     
    Last edited by a moderator: Oct 14, 2015
  2. Ray

    Ray

    You'll have to use FTP to publish your web application with VS 2010. How did you start your site? Did you use 'Web Application Project' or 'Web Site Project'?
     
  3. I started the project as "Silverlight Application" (my default is a C# setup).
    EDIT: i.e. I select "Silverlight Application", then select "ASP Web Project" as the auto-generated web project to host the app in.

    I can ftp them ok (using FileZilla), but I get errors which don't crop up when running it as a local test.

    Example here:

    www.illumidatumdb.com/MyWcfExperimentTestPage.html

    I suspect I can fix this particular one by adding this to <system.serviceModel>...

    <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
    <add prefix="http://YourWebsiteHostHeader" />
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>


    ...but wonder if that's because I've missed a basic step in creating this. When I was playing around with it (fixing bug after bug for an app which worked locally). Is it possible to define a series of steps which are required for this to work? Question swarming around my head include:

    Are there configuration steps required in IIS for an app this simple?
    Do I have to repoint the webservice from the randomly generated port to a specific online address for the service, or does it still locate it with "localhost"?

    I've seen options for packaging zip files which would then appear to be "run" on the server to set it up - is this a good approach, or to be avoided with shared hosting?

    So far I've not changed anything in the Web.config file - is there anything required (for example the possible fix above)?

    Apologies if something above is obvious but I must be missing something fairly fundamental. I can do the "codey bits" just not the "hosty bits"!

    Thanks again.
     
  4. Ray

    Ray

    The path is wrong. Its showing http://localhost:50666/MyWcfServices.svc. This is obviously the wrong path. You'll need to check your coding and update the path to your web service. Log into your hosting control panel and navigate to the Site Info Manager. There you will see your server path.
     
  5. Ok, so it's a question of re-pointing to the web service.

    I've tried updating the service reference in VS but it gives a 404 error. I tried navigating direct to the service in the browser and it's got an error:

    http://illumida.w01.Winhost.com/MyWcfService.svc

    Even though it's told explicitly to use .net 3.5 VS2010 appears to add "targetFramework = 4.0" to the Web.config. I've removed that and now have another error (see link above).

    There may to be a bug in VS2010 in that when you create a Silverlight App for 3.5 it doesn't let you decide the target framework for the associated website - it assumes .net 4. Trying to change it later produces all sorts of problems with missing references so I'll start a blank project and add bits in individually. I'll have to try that tomorrow (it's getting late here in the UK).

    Have I understood what you meant about the Site Info Manager, and the format of the service reference? I trust that what the path to my "live" web service should look like this...?

    http://illumida.w01.Winhost.com/MyWcfService.svc

    Thanks again for the blindingly fast responses. It's much appreciated.
     
    Last edited by a moderator: Oct 14, 2015
  6. Success!

    Finally cracked it. I'm posting the solution to a number of issues that others may bump into. Thanks again Ray...


    Problem 1: Target Framework
    Error: There's a quirk (read: bug) in VS2010 which means starting a Silverlight app for .net 3.5 with an auto-generated ASP project will still require .net 4.
    Solution: To circumvent, create the bsic project structure in VS2008 and then convert to VS2010.


    Problem 2: Multiple addresses per scheme
    Error: "This collection already contains an address with scheme http. There can be at most one address per scheme in this collection."
    Solution: Search in Web.config for <system.serviceModel>, add this on next line:
    <serviceHostingEnvironment>
    <baseAddressPrefixFilters>
    <add prefix="http://YourWebsiteHostHeader" />
    </baseAddressPrefixFilters>
    </serviceHostingEnvironment>



    Problem 3: wsHttpBinding Binding
    Error: Can't remember exact error but something moaning about wsHttpBinding
    Solution: In Web.config change...
    <endpoint address="" binding="wsHttpBinding" contract="IService">
    To this:
    <endpoint address="" binding="basicHttpBinding" contract="IService">


    Problem 4: Cross Domain Policy
    Error: Again, can't remember exact error but something moaning about cross-domain access
    Solution: Create a new xml file in the host site called "crossdomainpolicy.xml" based on the info here:
    Tim Heuer's Blog


    Problem 5: Me not quite quite getting the gist (!)
    Error: Various screwy behaviour which changes every time it's run...
    Solutions: If things aren't quite working out try a few of the following ideas / notes...

    - Whilst your web service may work locally with ...localhost:12345... for the final thing you need to point it to a physical webservice that's already there. Upload your project via ftp and then "Update Service Reference" and type in the direct url of the service then hit GO. e.g. www.mydomain.com/myservice.svc

    - If in doubt rebuild, re-upload and try again

    - If your App isn't working as you'd expect clear the cache of your browser and refresh (you might be running an out of date copy of your app even if it's in local debugger)


    Hope you have less trouble than I did.

    (PS - for those new to IIS like myself, this involved no fiddling with IIS Manager whatsoever - purely the steps above to get a basic web service working)
     
  7. Thanks for that detailed follow up!
     
  8. No worries - I know how annoying it is when you find a thread that has the same problem as you and it ends in either nothing or "Fixed it!" and nothing else!

    Hopefully this'll help someone else get going.

    I'll be trying to connect through to the database with the Web Service next so I'm sure there'll be more frustrated posts from me in due course.
     

Share This Page