Calling the Service
WCF supports several ways to create and configure a client to call a service. First, as was the
case with hosting a service, the calling code can exist within any type of application—web
application, Windows application, even another WCF service.
Regardless of the client application type you choose, the client requires several bits of
information to successfully call the service.
• The service contract : This can be any local type (class or interface) that adheres to the
contract published by the service endpoint.
• The service address: This should be the same address configured in the service end-
point.
• The service binding: The client must use the same protocols, transport, and encoding as
the service endpoint.
Notice that these three pieces of information match the information exposed by the service
endpoint exactly. In fact, the client must use this information to establish a client-side end-
point. Similar to the service endpoint, the client-side endpoint establishes the communi-
cation plumbing going up to the service and also manages the message exchange.
WCF does not care exactly how all this information gets to the client. You could, for exam-
ple, manually code the contract type into the client and set the proper address and binding in
the configuration file. Here’s what this might look like:
// This must adhere to the service contract, but does NOT need
// to be named the same.
[ServiceContract]
interface INotTheSameNameAsService
{
[OperationContract]
int Add(int n1, int n2);
[OperationContract]
int Subtract(int n1, int n2);
}











0 comments:
Post a Comment