Microsoft 9GD00001 Computer Accessories User Manual


 
328 Microsoft Visual Studio 2010: A Beginner’s Guide
put http://localhost:8080/WcfDemo.CustomerService.svc into the Address box. In the
deployed service, the service name might not be WcfDemo.CustomerService.svc as shown
in this demo. To find out what the real service name file should be, navigate to the physical
directory where the service was deployed to and use the file name of the *.svc file. Sometimes,
you’ll need to use Web services by third parties or another organization in your company. In
those cases, you’ll get the address to use from a person in the other organization or read their
documentation to learn what address to use. If you add your own address, click Go to get more
information on the Web service.
After either clicking Discover or adding an address and clicking Go, you’ll have
one or more services in the Services list. At this point, if you receive an error, it will be
because the address is incorrect, the service is experiencing an outage, or (in the case
of referencing a service in your own project) the service won’t compile. First check the
address if you entered it yourself. If you are referencing a project in your solution, go back
and recompile the Web Service project to make sure it builds, fix any problems, and try
to create the service reference again. Once you’ve ensured that you’ve corrected all the
problems on your side of the wire, contact whoever owns the Web service to troubleshoot
the problem.
When a Web service can be communicated with successfully, you’ll see the list
of services. You can drill down on each service until you find the interface for the
service you’re interested in. In Figure 11-11, the ICustomerService is selected, which
displays all available operations. Looking back at the previous discussion of creating
the CustomerService, you can see the interface that was created and the methods. If you
don’t see an interface or a method, check the attributes in the code to ensure the interface
has a ServiceContract attribute and that any methods that should be exposed have an
OperationContract attribute.
The Web service will create a proxy, which is a class that communicates with the Web
service, in your project, using the default namespace declared in the Properties for your
project. The namespace in the Add Service Reference defaults to Service1, and you’ll want
to change that to something meaningful, such as CustomerService, as shown in Figure 11-11.
This will result in a proxy class created in MyProjectNamespace.CustomerService. This is
important to know because you will need to create an instance of the proxy and must know
the namespace that the proxy resides in. Click OK to create the service reference such as the
one shown in Figure 11-12.
As you can see in Figure 11-12, the project has a new folder, named Service References.
The CustomerService reference under ServiceReferences is named after the namespace you
specified in the Add Service Reference window.