PETR
programming c# 4.0.pdf

Imagine a wpf application providing some sort of

Info icon This preview shows pages 511–513. Sign up to view the full content.

Imagine a WPF application providing some sort of advertising display on a screen in a shop window—it could be useful to build a WCF service into this to enable the display to be controlled without needing physical access to the machine. The techniques for hosting look much the same in all cases. And since we won’t be getting on to ASP.NET until later in the book, we’ll keep it simple by hosting our service in a console application. It’ll be easy enough to move it into different hosting environ- ments later because the service itself is in a separate DLL project—we could just add it to a Windows Service or a web application. Regardless of the type of host, one of the most important parts of WCF hosting is the configuration file. WCF configuration If you look in the ChatServerLibrary project, you’ll find an App.config file. You’ll find one of these, or its web equivalent, web.config , in lots of different kinds of .NET ap- plications, but an App.config in a library project is something of an anomaly— application configuration files configure applications , and a library is not an application. Normally, adding an App.config file to a project that builds a DLL does nothing useful, but WCF projects are an exception because of the WCF Service Host we saw earlier. The test host loads the contents of this file into its own application configuration. Normally, application configuration files must go either into projects that build exe- cutable applications, or into web projects. The App.config in a WCF Service Library project is used only by the WCF Service Host. You will always need to copy the configuration into your real service host application. WCF | 487
Image of page 511

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

So that we can have an application to configure, we’ll add a console application called ChatHost to our WcfChat solution. This console application will host our WCF service, so we’ll add a reference to the ChatServerLibrary . And since we’ll be using this console application as the host from now on instead of WcfSvcHost , we’ll need to copy the configuration in the ChatServerLibrary project’s App.config into the ChatHost project’s App.config . (Once we’ve done this, we can delete the App.config in the ChatServerLi brary project.) We’ll look at each of the App.config file’s sections to understand how the file works. Everything lives inside the root <configuration> element—all App.config and web.config files have one of these, no matter what sort of application you’re writing. The first child element will be this: <system.web> <compilation debug="true" /> </system.web> Our example doesn’t need this, so it’s safe to delete it. The WCF Service Library tem- plate adds this in case you are planning to host the project in a web application—this enables debugging in web apps. But since we’re not writing a web application, it’s not needed here.
Image of page 512
Image of page 513
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '15

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern