Uses this information to configure a client

Info icon This preview shows pages 519–521. Sign up to view the full content.

View Full Document Right Arrow Icon
uses this information to configure a client application to communicate with the service, and to provide it with a copy of the contract. To see the results of this, we’ll finish with this dialog. In the Namespace text box near the bottom, we’ll type ChatService —Visual Studio will put the contract and any other types relating to this service into this namespace. When we click OK a Service Refer- ences item appears in the project in the Solution Explorer, and it will contain an entry called ChatService . (Now that we’ve done this, we can stop the service host console window we ran earlier.) Visual Studio generates some code when adding a service reference. By default, it hides this, but we can take a look at it. At the top of the Solution Explorer, there’s a toolbar, and if you hover your mouse pointer over the buttons you’ll find that one has a tool tip of Show All Files. This button toggles each time you click it. When it’s pressed in, the ChatService service reference can be expanded, as Figure 13-7 shows. Figure 13-7. Generated files in a service reference The most interesting file in here is Reference.cs , inside the Reference.svcmap item. Inside this file, near the top, there’s a copy of IChatService —the contract we wrote earlier: [System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")] [System.ServiceModel.ServiceContractAttribute( ConfigurationName="ChatService.IChatService"] public interface IChatService { [System.ServiceModel.OperationContractAttribute( Action="http://tempuri.org/IChatService/PostNote", ReplyAction="http://tempuri.org/IChatService/PostNoteResponse")] void PostNote(string from, string note); } WCF | 495
Image of page 519

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

View Full Document Right Arrow Icon
It looks a little more complex than the original, because Visual Studio has annotated it with various attributes, but it’s simply being explicit about the values that WCF fills in by default. Aside from these extra details, you can see that it is essentially a copy of the original contract. Sharing contracts You might wonder why we jumped through all these hoops rather than just copying IChatService from the service project to the client. In fact, that would have worked, and we could even have written a separate DLL project to define the contract interface and shared that DLL across the two projects. As you’ll see shortly, Visual Studio gen- erated a few other useful things for us as part of this Add Service Reference process, but as it happens, sharing the contract definition directly is sometimes a perfectly rea- sonable thing to do—you’re not obliged to use metadata exchange. Of course, you won’t always own the code at both ends. If you need to connect to a service on the Internet provided by someone else, metadata exchange becomes more important—it provides a way to get hold of a contract you didn’t write. And since the metadata exchange mechanisms are standards-based, this can work even when the service is not written in .NET.
Image of page 520
Image of page 521
This is the end of the preview. Sign up to access the rest of the document.

{[ 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