WCF’s most important aspects:
- Unification of the original .NET Framework communication technologies
- Interoperability with applications built on other technologies
- Explicit support for service-oriented development.
- ASMX, also called ASP.NET Web Services, would be an option for communicating with the Java to achieve cross-vendor interoperability.
- .NET Remoting is a natural choice for .NET-to-.NET communication
- Distributed Transactions
- Web Services Enhancements (WSE) might be used along with ASMX to communicate with the Java EE-based reservation application and with the partner applications.
- System.Messaging, which provides a programming interface to Microsoft Message Queuing (MSMQ), could be used to communicate with Windows-based partner applications that weren’t always available. The persistent queuing that MSMQ provides is typically the best solution for intermittently connected applications.
- System.Net might be used to communicate with partner applications or perhaps in other ways. Representational State Transfer (REST)
[ServiceContract]
class RentalReservations
{
[OperationContract]
public bool Check(int vehicleClass, int location, string dates)
{
bool availability;
// code to check availability goes here
return availability;
}
public int GetStats()
{
int numberOfReservations;
// code to get the current reservation count goes here
return numberOfReservations;
}
}
Using explicit interfaces like this is slightly more complicated, but it allows more flexibility. For example, a class can implement more than one interface, which means that it can also implement more than one service contract.
using System.ServiceModel;
[ServiceContract]
interface IReservations
{
[OperationContract]
bool Check(int vehicleClass, int location, string dates);
}
class RentalReservations : IReservations
{
public bool Check(int vehicleClass, int location, string dates)
{
bool availability;
// logic to check availability goes here
return availability;
}
public int GetStats()
{
int numberOfReservations;
// logic to determine reservation count goes here
return numberOfReservations;
}
}
using System.Runtime.Serialization;
[DataContract]
struct ReservationInfo {
[DataMember] public int vehicleClass;
[DataMember] public int location;
[DataMember] public string dates;
}
reserve.svc
<%@Service language=c# class="RentalReservations" %>
- IIS-hosted WCF services can only be accessed using SOAP over HTTP. No other transport protocols are supported.
- Although WAS doesn’t require a Web server to be installed on the system, WCF services hosted in IIS obviously do.
Defining Endpoints
- An address indicating where this endpoint can be found. Addresses are URLs that identify a machine and a particular endpoint on that machine.
- A binding determining how this endpoint can be accessed. The binding determines what protocol combination can be used to access this endpoint along with other things, such as whether the communication is reliable and what security mechanisms can be used.
- A contract name indicating which service contract this WCF service class exposes via this endpoint. A class marked with ServiceContract that implements no explicit interfaces, such as RentalReservations in the first example shown earlier, can expose only one service contract. In this case, all its endpoints will expose the same contract. If a class explicitly implements two or more interfaces marked with ServiceContract, however, different endpoints can expose different contracts, each defined by a different interface.
Creating a WCF Client
Creating a proxy requires knowing what contract is exposed by the target endpoint, and then using the contract’s definition to generate the proxy. In WCF, this process can be performed using either Visual Studio or the command-line svcutil tool.Windows Communication Foundation
No comments:
Post a Comment