0% found this document useful (0 votes)
6 views22 pages

Windows

Winfows

Uploaded by

Rama Subramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views22 pages

Windows

Winfows

Uploaded by

Rama Subramanian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

WPF

WPF stands for Windows Presentation Foundation. It is a powerful framework for building Windows applications. Windows
Presentation Foundation (WPF) is a library to create the UI for smart client applications.
WPF – Advantages
In the earlier GUI frameworks, there was no real separation between how an application looks like and how it behaved. Both GUI
and behavior was created in the same language, e.g. C# or VB.Net which would require more effort from the developer to
implement both UI and behavior associated with it.
In WPF, UI elements are designed in XAML while behaviors can be implemented in procedural languages such C# and VB.Net. So
it very easy to separate behavior from the designer code.

Namespaces
Classes from Windows Forms and WPF can easily be confused. The Windows Forms classes are located in the
System.Windows.Forms namespace, and the WPF classes are located inside the namespace System.Windows and
subnamespaces thereof, with the exception of System.Windows.Forms. For example, the
Button class for Windows Forms has the full name System.Windows.Forms.Button, and the Button class for WPF has the full
name System.Windows.Controls.Button.
SHAPES
WPF
Shapes are the core elements of WPF. With shapes you can draw two-dimensional graphics using rectangles,lines, ellipses, paths, polygons,
and polylines that are represented by classes derived from the abstract base class Shape. Shapes are defi ned in the namespace
System.Windows.Shapes.
The following XAML example (code fi le ShapesDemo/MainWindow.xaml) draws a yellow face consisting of an ellipse for the face, two
ellipses for the eyes, two ellipses for the pupils in the eyes, and a path for the mouth
<Window x:Class="ShapesDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="300">
<Canvas>
<Ellipse Canvas.Left="10" Canvas.Top="10" Width="100" Height="100"
Stroke="Blue" StrokeThickness="4" Fill="Yellow" />
<Ellipse Canvas.Left="30" Canvas.Top="12" Width="60" Height="30">
<Ellipse.Fill>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5, 1">
<GradientStop Offset="0.1" Color="DarkGreen" />
<GradientStop Offset="0.7" Color="Transparent" />
</LinearGradientBrush>
</Ellipse.Fill>
WPF
<Ellipse Canvas.Left="65" Canvas.Top="35" Width="25" Height="20" Stroke="Blue"
StrokeThickness="3" Fill="White" />
<Ellipse Canvas.Left="75" Canvas.Top="43" Width="6" Height="5" Fill="Black" />
<Path Name="mouth" Stroke="Blue" StrokeThickness="4"
Data="M 40,74 Q 57,95 80,74 " />
</Canvas>
</Window>
WPF
SHAPE CLASS DESCRIPTION

Line You can draw a line from the coordinates X1.Y1 to X2.Y2.

Rectangle Enables drawing a rectangle by specifying Width and Height

Ellipse With the Ellipse class, you can draw an ellipse


Path You can use the Path class to draw a series of lines and curves. The
Data property is a Geometry type. You can do the drawing by using
classes that derive from the base class Geometry, or you can use the
path markup syntax to define geometry
Polygon Enables drawing a closed shape formed by connected lines with the
Polygon class. polygon is defi ned by a series of Point objects assigned
to the Points property.

Polyline Similar to the Polygon class, you can draw connected lines with
Polyline. The diff erenceis that the polyline does not need to be a
closed shape.
WPF
TRANSFORMATION
• Because WPF is vector-based, you can resize every element. In the next example, the vector-
based graphics are now scaled, rotated, and skewed.Coding for scaling

• scaling
Adding the ScaleTransform element to the LayoutTransform property of the Canvas element, as
shown
here (code fi le TransformationDemo/MainWindow.xaml), resizes the content of the complete
canvas by 1.5
in the x and y axes:
<Canvas.LayoutTransform>
<ScaleTransform ScaleX="1.5" ScaleY="1.5" />
</Canvas.LayoutTransform>

• Rotation
• Using the RotateTransform element you can defi ne the Angle for the rotation:
<Canvas.LayoutTransform>
<RotateTransform Angle="40" />
</Canvas.LayoutTransform>
WPF
For skewing, you can use the SkewTransform element,
<Canvas.LayoutTransform>
<SkewTransform AngleX="20" AngleY="25" />
</Canvas.LayoutTransform>
WPF
BRUSHES
• WPF offers brushes for drawing backgrounds and foregrounds.
SolidColorBrush
SolidColorBrush, which, as the name suggests,uses a solid color. The complete area is
drawn with the same color.
<Button Content="Solid Color" Margin="10">
<Button.Background>
<SolidColorBrush Color="PapayaWhip" />
</Button.Background>
</Button>
WPF
• LinearGradientBrush
For a smooth color change, you can use the LinearGradientBrush, as the second button shows. This
brush defi nes the StartPoint and EndPoint properties. With this, you can assign two-dimensional
coordinates for the linear gradient. The default gradient is diagonal linear from 0,0 to 1,1. By defi
ning
different values, the gradient can take different directions. For example, with a StartPoint of 0,0 and
an
EndPoint of 0,1, you get a vertical gradient. The StartPoint and EndPoint value of 1,0 creates a
horizontal gradient.
<Button Content="Linear Gradient Brush" Margin="10">
<Button.Background>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="LightGreen" />
<GradientStop Offset="0.4" Color="Green" />
<GradientStop Offset="1" Color="DarkGreen" />
</LinearGradientBrush>
</Button.Background>
</Button>
WPF
• RadialGradientBrush
With the RadialGradientBrush you can smooth the color in a radial way. In Figure 35-8,
the third element
is a Path that uses RadialGradientBrush. This brush defi nes the color start with the
GradientOrigin
point (code fi le BrushesDemo/MainWindow.xaml):
<Canvas Width="200" Height="150">
<Path Canvas.Top="0" Canvas.Left="20" Stroke="Black" >
<Path.Fill>
<RadialGradientBrush GradientOrigin="0.2,0.2">
<GradientStop Offset="0" Color="LightBlue" />
<GradientStop Offset="0.6" Color="Blue" />
<GradientStop Offset="1.0" Color="DarkBlue" />
</RadialGradientBrush>
WCF
• WCF stands for Windows Communication Foundation. It is a framework for building, configuring, and deploying
network-distributed services. The elementary feature of WCF is interoperability. It is one of the latest
technologies of Microsoft that is used to build service-oriented applications. Based on the concept of message-
based communication, in which an HTTP request is represented uniformly. WCF platform is also known as the
Service Model.
The namespace for WCF is System.ServiceModel.
Fundamental Concepts of WCF
Message-This is a communication unit that comprises of several parts apart from the body. Message instances are
sent as well as received for all types of communication between the client and the service.
Endpoint-It defines the address where a message is to be sent or received. It also specifies the communication
mechanism to describe how the messages will be sent along with defining the set of messages
Address-Address specifies the exact location to receive the messages and is specified as a Uniform Resource
Identifier (URI).
Binding-It defines the way an endpoint communicates. It comprises of some binding elements that make the
infrastructure for communication. For example, a binding states the protocols used for transport like TCP, HTTP,
etc., the format of message encoding, and the protocols related to security as well as reliability.
Contracts-It is a collection of operations that specifies what functionality the endpoint exposes to the client. It
generally consists of an interface name.
Hosting-Hosting from the viewpoint of WCF refers to the WCF service hosting which can be done through many
available options like self-hosting, IIS hosting, and WAS hosting.
WCF

The final goal is to send and receive messages between a client and a service across
processes or different systems,across a local network, or across the Internet. This should
be done, if required, in a platform-independent way and as fast as possible. From a
distant view, the service offers an endpoint that is described by a contract, a binding,
and an address. The contract defi nes the operations offered by the service; binding gives
information about the protocol and encoding; and the address is the location of the
service. The client needs a compatible endpoint to access the service.
WCF
The client invokes a method on the proxy. The proxy offers methods as defi ned by the
service but converts the method call to a message and transfers the message to the
channel. The channel has a client-side part and a server-side part that communicate
across a networking protocol. From the channel, the message is passed to the dispatcher,
which converts the message to a method call invoked with the service.WCF supports
several communication protocols. For platform-independent communication, web
services standards are supported. For communication between .NET applications, faster
communication protocols with less overhead can be used.
The following sections look at the functionality of core services used for platform-
independent communication:
• ➤ SOAP — A platform-independent protocol that is the foundation of several web
service specifi cations to support security, transactions, reliability
• ➤ Web Services Description Language (WSDL) — Offers metadata to describe a
service
• ➤ Representational State Transfer (REST) — Used with RESTful Web services to
communicate across HTTP
• ➤ JavaScript Object Notation (JSON) — Enables easy use from within JavaScript
clients
WCF
• SOAP
For platform-independent communication, the SOAP protocol can be used and is directly supported from WCF. SOAP
originally was shorthand for Simple Object Access Protocol (SOAP), but since SOAP 1.2 this is no longer the case. SOAP
no longer is an object access protocol because instead messages are sent that can be defi ned by an XML schema.A
service receives a SOAP message from a client and returns a SOAP response message. A SOAP message consists of an
envelope, which contains a header and a body:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
</s:Header>
<s:Body>
<ReserveRoom xmlns="http://www.cninnovation.com/RoomReservation/2012">
<roomReservation
• xmlns:a="http://schemas.datacontract.org/2004/07/Wrox.ProCSharp.WCF.Contracts"
• xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
• <a:Contact>UEFA</a:Contact>
• <a:EndTime>2012-07-01T22:45:00</a:EndTime>
• <a:Id>0</a:Id>
• <a:RoomName>Kiew</d4p1:RoomName>
• <a:StartTime>2012–07–01T20:45:00</a:StartTime>
• <a:Text>Spain-Germany</a:Text>
• </roomReservation>
• </ReserveRoom>
• </s:Body>
• </s:Envelope>
WCF
• WSDL
A Web Services Description Language (WSDL) document describes the operations and
messages of the
service. WSDL defi nes metadata of the service that can be used to create a proxy for the
client application.
The WSDL contains this information:
➤ Types for the messages described using an XML schema.
➤ Messages sent to and from the service. Parts of the messages are the types defi ned
with an XMLschema.
➤ Port types map to service contracts and list operations defi ned with the service
contract. Operationscontain messages; for example, an input and an output message as
used with a request and response sequence.
Binding information that contains the operations listed with the port types and that defi
nes the SOAPvariant used.
➤ Service information that maps port types to endpoint addresses.
WCF
• REST
WCF also offers communication by using REST. This is not actually a protocol but defi nes
several principles for using services to access resources. A RESTful Web service is a
simple service based on the HTTP protocol and REST principles. The principles are defi
ned by three categories: a service can be accessed with a simple URI, supports MIME
types, and uses different HTTP methods. With the support of MIME types, different data
formats can be returned from the service such as plain XML, JSON, or AtomPub. The GET
method of a HTTP request returns data from the service. Other methods that are used are
PUT, POST, and DELETE. The PUT method is used to make an update on the service side,
POST creates a new resource, and DELETE deletes a resource. REST enables the sending
of smaller requests to services than is possible with SOAP. If transactions, secure
messages, (secure communication is still possible, for example via HTTPS), and the
reliability offered by SOAP are not needed, a REST-architected service can reduce
overhead. With the REST architecture, the service is always stateless, and the response
from the service can be cached
• JSON Instead of sending SOAP messages, accessing services from JavaScript can best
be done by using JSON. .NET includes a data contract serializer to create objects with
the JSON notation. JSON has less overhead than SOAP because it is not XML but is
optimized for JavaScript clients. This makes it extremely useful from Ajax clients. JSON
does not provide the reliability, security, and transaction features that can be sent with
the SOAP header, but these are features usually not needed by JavaScript clients.
webservices
We can now use ASP.NET to create Web Services based on industrial standards including XML, SOAP, and
WSDL.
A Web Service is a software program that uses XML to exchange information with other software via common
internet protocols. In a simple sense, Web Services are a way of interacting with objects over the Internet.
A web service is
Language Independent.
Protocol Independent.
Platform Independent.
It assumes a stateless service architecture.
Scalable (e.g. multiplying two numbers together to an entire customer-relationship management system).
Programmable (encapsulates a task).
Based on XML (open, text-based standard).
Self-describing (metadata for access and use).
Discoverable (search and locate in registries)- ability of applications and developers to search for and locate
desired Web services through registries. This is based on UDDI.
webservices
Key Web Service Technologies
XML- Describes only data. So, any application that understands XML-regardless of the application's programming
language or platform has the ability to format XML in a variety of ways (well-formed or valid).
SOAP- Provides a communication mechanism between services and applications.
WSDL- Offers a uniform method of describing web services to other programs.
UDDI- Enables the creation of searchable Web services registries.
Web services advantages
Use open, text-based standards, which enable components written in various languages and for different platforms
to communicate.
Promote a modular approach to programming, so multiple organizations can communicate with the same Web
service.
Comparatively easy and inexpensive to implement, because they employ an existing infrastructure and because
most applications can be repackaged as Web services.
Significantly reduce the costs of enterprise application (EAI) integration and B2B communications.
Implemented incrementally, rather than all at once which lessens the cost and reduces the organizational
disruption from an abrupt switch in technologies.
The Web Services Interoperability Organization (WS-I) consisting of over 100 vendors promotes interoperability.
webservices
Step 1- Create the ASP.NET Web Service Source File
Open Visual Studio 2010 and create a new web site.->Select .Net Framework 3.5. ->Select ASP.NET Web Service page -> Then, you
have to give the name of your service. In this example, I am giving its name "mywebservice". Then Click the ok Button. A screen-shot of
this activity is given below.
webservices
Step 2- click on the "ok" button; you will see the following window .
webservices
Here (in the above figure), you will note that there is predefined method "HelloWorld" which returns the string "Hello World". You can use your
own method and can perform various operations. Here I made a simple method which returns the multiplication of two numbers using the code .
1. using System;

2. using System.Collections.Generic;

3. using System.Linq;

4. using System.Web;

5. using System.Web.Services;

6. [WebService(Namespace = "http://tempuri.org/")]

7. [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

8. // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.

9. // [System.Web.Script.Services.ScriptService]

10.public class Service : System.Web.Services.WebService

11.{

12. [WebMethod]

13. public int Multiplication(int a,int b)

14. {

15. return (a*b);

16. }

17.}
webservices
• The [WebMethod] attribute
• The Service class exposes a single method, the public method Multiplication, which takes two integer arguments and returns
the multiplication of two number as integer. To expose a method as a part of a web service, you must decorate it with the
WebMethod attribute, which tells the compiler to treat it as such. Any method marked with the WebMethod attribute must be
defined as public. Class methods exposed as web services follow the same object-oriented rules as any other class, and
therefore methods marked private, protected, or internal are not accessible and will return an error if you attempt to expose
them using the WebMethod attribute.
Step 3- Build Web Service and Run the Web Service for testing by pressing F5 function key .
webservices

You might also like