Advantage
Endpoints will be mentioned in the web.config file on the created service.
- WCF is interoperable with other services when compared to .Net Remoting,where the client and service have to be .Net.
- WCF services provide better reliability and security in compared to ASMX web services.
- In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.
- WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality. In other technology developer has to write the code.
| Features | Web Service | WCF |
|---|---|---|
| Hosting | It can be hosted in IIS | It can be hosted in IIS, windows activation service, Self-hosting, Windows service |
| Programming | [WebService] attribute has to be added to the class | [ServiceContraact] attribute has to be added to the class |
| Model | [WebMethod] attribute represents the method exposed to client | [OperationContract] attribute represents the method exposed to client |
| Operation | One-way, Request- Response are the different operations supported in web service | One-Way, Request-Response, Duplex are different type of operations supported in WCF |
| XML | System.Xml.serialization name space is used for serialization | System.Runtime.Serialization namespace is used for serialization |
| Encoding | XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom | XML 1.0, MTOM, Binary, Custom |
| Transports | Can be accessed through HTTP, TCP, Custom | Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom |
| Protocols | Security | Security, Reliable messaging, Transactions |
Endpoints will be mentioned in the web.config file on the created service.
<system.serviceModel><services> <service name="MathService" behaviorConfiguration="MathServiceBehavior"> <endpoint address="http://localhost:8090/MyService/MathService.svc" contract="IMathService" binding="wsHttpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MathServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
- There could be more than 1 end points in a webconfig.
- for example, One of the client will access SOAP using http and other client will access Binary using TCP. How it can be done?
- <system.serviceModel>
<services> <service name="MathService" behaviorConfiguration="MathServiceBehavior"> <endpoint address="http://localhost:8090/MyService/MathService.svc" contract="IMathService" binding="wsHttpBinding"/><endpoint address="net.tcp://localhost:8080/MyService/MathService.svc" contract="IMathService" binding="netTcpBinding"/> </service> </services> <behaviors> <serviceBehaviors> <behavior name="MathServiceBehavior"> <serviceMetadata httpGetEnabled="True"/> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> </system.serviceModel>
---------------------------------------------
>> Addresss contain the location of service and transport schema.
HTTP, TCP, MSMQ, Peer Network
>> example, http://localhost/service/callme
net.tcp://localhost/service/callme
>> ABC (end points)
>> Contracts type
Service Contract
Data Contract
Fault Contract
Message contract
>> [ServiceContract] - defines which operation client can perform on services.
sub types -
1) service contract - define interfaces.
2) operation contract - define methods inside interfaces.
>> [servicecontract]
interface Icontract
{
[operationcontract]
string myMethod();
}
Class Myservice:Icontract
{
public string myMethod()
{ return "hello"; }
}