Post on 08-Jun-2018
Naresh InformationTechnologiesTechnologies
Nagaraju BendeMCPD.NET Sr Consultant,Trainer
http://nbende.wordpress.com
Consuming WCF Services
VS.NET Role in building WCF Apps
Agenda – Session 4
�������������� �����������������
WCF Service Library & WCF Service
Data Contracts
<system.serviceModel> <services> <endpoint address = "http://localhost:8000/CustomerManager" binding = "basicHttpBinding" contract = "IContactManager"> </endpoint> </services> </system.serviceModel>
Addresses
�������������� �����������������
</system.serviceModel>
<system.serviceModel> <services> <endpoint address = "net.tcp://localhost:8001/CustomerManager/" binding = "netTcpBinding" contract = "IContactManager"> </endpoint> </services> </system.serviceModel>
Develop Real World WCF Service Library
WCFTESTCLIENT.exe / WCFSVCHost.exe
Agenda – Session 5
�������������� �����������������
Host in Windows Service
Configure more bindings
WCF Service using Web Template
Hosting in Web Server
Agenda – Session 6
�������������� �����������������
LinqToSql/ADO.NET Entities/WCF
Demo
IIS Hosting – simple 3 steps
1 Create Virtual Directory in IIS
Create .svc file for service
�������������� �����������������
2 Create .svc file for service implementation
3 Configuration of web.config for services
Web Programming using WCF
WCF for ASP.NET AJAX apps
Agenda – Session 9
�������������� �����������������
webHttpBinding new in 3.5, VS.NET role
SOAP, JSON, POX, REST styles
Demo
webHttpBinding
• New “web-friendly” WCF Binding in Fx 3.5– Allows for the development of RESTful services– Does not use SOAP envelopes– HTTP and HTTPS Transports Only
• Supports several wire formats:
�������������� �����������������
• Supports several wire formats:– XML– JSON– Binary (streams)
• JavaScript Object Notation• Format for bridging JavaScript and objects
– Easier for browsers than XML
• ASP.NET AJAX & other AJAX toolkits use it
What is JSON?
�������������� �����������������
• ASP.NET AJAX & other AJAX toolkits use it– Other web-aware clients also (Silverlight, etc.)
������������ ����������� ������������������ ������������������ ������������������ ����������������������� ��������� �� ��������� �� ��������� �� ��������� ��
������������������������������������������������ �� ���� ������!��� ���� ������!��� ���� ������!��� ���� ������!�������������������������������������"�"�"�"�
• WCF AJAX support in Visual Studio – Script manager, VS Project Templates
• WCF automatically generates JS proxy• Usage pattern similar to existing one:
– Add service to Script Manager control
WCF / AJAX Integration
�������������� �����������������
– Add service to Script Manager control– Write JavaScript code to work with proxy
• Configuration not required– Via the WebScriptServiceHostFactory (.svc file)
SOAP, JSON, POX, REST styles
WebGet and WebInvoke
Agenda – Session 10
�������������� �����������������
UriTemplate in 3.5
Demo
[WebGet] And [WebInvoke]
• Binds a WCF operation to URI space and HTTP method
• Indicate the HTTP Method for the operation– WebGet – Don’t make me write it– WebInvoke – All verbs other than GET (Method
�������������� �����������������
– WebInvoke – All verbs other than GET (Method parameter takes in the name of the Verb)
• Other Parameters– BodyStyle – Indicates whether the Request/
Response are wrapped or not– RequestFormat – Json or Xml– ResponseFormat – Json or Xml– UriTemplate – Rich binding to URI
UriTemplate
• String that allows you to define the structure of the URI, as well as to define “Holes” – The “Holes” are variables– You Bind the template with parameters to
�������������� �����������������
– You Bind the template with parameters to fill the holes
• {productId} hole / variable gets bound to productId parameter in operation
��������������
����������������������������������������
����� ��� �������� ����������
��������
WCF REST Starter Kit
• Microsoft.ServiceModel.Web.dll– New features supporting RESTful services
• Visual Studio 2008 Templates– REST Collections/Singleton Services
�������������� �����������������
– Atom Feed/Atom Publishing Protocol– HTTP/POX Services
• REST Samples• Codeplex Project
– Released at PDC– Written by WCF team– Features may be included in .NET 4.0