Web Services Overview

acceptableseashoreΑσφάλεια

5 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

117 εμφανίσεις

G53ELC

Dave Elliman

Practical .NET

G53ELC

The .NET Framework
Architecture

Microsoft .NET Framework

System Services

Common Language Runtime

ASP.NET

Web
Services

Windows Forms

Services Framework

Base

Data

Debug

...

Silverlight

Web
Forms

G53ELC

Programming model

Common Language Runtime

Execution Engine

CIL &

Metadata

Class

Lib

Class Loader

Managed

native

Code

Execution

Compiler

JIT Compiler

Source

Code

G53ELC

What Types of Application

Will .NET Support

All types!


G53ELC

Console Applications


Build Command Line Executables


Use Any .NET Language


Very Light Weight


Hello World ~ 5k

G53ELC

Windows Forms


Descended from Windows Foundation
Classes


Common framework for all applications


Standard API for Windows services in
graphics and drawing


Easier to update than former Visual
Basic applications


G53ELC

Windows Forms


Desktop Applications


Form Based


Database Front
-
End


SDI/MDI


Printing


Page settings


Print Preview


WPF with XAML the approach of choice
now

G53ELC

Separate Look from Action


XAML (pronounced ZAML) for declaritive
specification of view


Code behind in C# (or any CLR)


In enterprise applications code could run
on a server with view on a client.


State of the art widgets and appearance

G53ELC

Windows Services


Build Services in any .NET Language


Process Installer


Writes registry entries


Identity


User Name


Password


System Account


Start Type


Manual



Automatic


Disabled

G53ELC

Dynamic Web Pages


Using ASP.NET

G53ELC

What Is ASP.Net


The next version of ASP for IIS


Runs noticeably faster


JIT, Cache etc
i.e. compiled unlike old ASP


Based on CLR (Common Language
Runtime)


Common tasks for web applications made
easy. Logins, forms etc.


Scalability, availability, security,
transaction support is all there


G53ELC

Web 2.0 Apps


Silverlight


Attractive visual effects


Lightweight run
-
time


Browser independent


SILVERLIGHT

G53ELC

Web services


Very flexible support for all kinds of web
service, protocols and authentication in
WCF

G53ELC

Illustrating Web Services
Technologies

UDDI
Registry

Internet

UDDI
Registry

Application

WSDL Interface

Application

Application

SOAP

G53ELC

Asp.NET
-

Web Services


Software as a service without concern for the
type of consumer


Programmes speak to one another over the web
via SOAP or RESTFUL approach


Configurable using WCF

G53ELC

Web Services: A reminder


A Paradigm for distributed computing
-

loosely coupled


Allows SOA (Servive oriented
architectures) sync or async


Allows disparate systems to work
together


Based on open standards

G53ELC

Configuration


Concepts and architecture


Web.Config file. Xml OF COURSE!


<webServices>

section

Server

Root

Dir

Web.Config

G53ELC

Creating A Web Service


Make a
.asmx

file and put it in the
server directory (IIS)


It will contain script in
C#


Or maybe VB.NET, J#, or managed C++
(even IronPython)

G53ELC

Sample .asmx file

<%@ WebService Language=

C#


Class=

MathService


%>

using System;

using System.Web.Services;


public class MathService {


[WebMethod]


public int Subtract(int a, int b)


{


return a
-

b;


}



public int Subtract_vs(int a, int b)


{


return b
-

a;


}

}

G53ELC

Publishing a
Web Service


There is a wsdl tool that creates the web
service for you


This is all built into Visual Studio .NET


Web Service clients


Can be Web applications or browsers

G53ELC

Consuming Web Services


Usually typing the url in a browser


Add ?wsdl to url to get the description which
defines the interface


e.g. http://www.xmlme.com/WSShakespeare.asmx

G53ELC

http://www.uddi.org/



A good place to start exploring for web
services


You will need to register but its free

G53ELC

Sample WSDL file

<definitions name=“
serviceName
“>


<import namespace=“http://
namespacePath



location=“http://
path
/
fileName.wsdl
“>


<portType name=“serviceNamePortType“>


<operation name=“opName“>


<input message=“msgNameInput“ />


<output message=“msgNameOutput“ />


</operation>


</portType>


<binding name=“serviceNameSoapBinding“>


<soap:operation soapAction=“http://...“ />


</binding>


<service name=“
serviceName
“>


<port name=“
serviceNamePort
“ binding=“bindingName“>


<soap:address location="http://..." />


</port>


</service>

</definitions>

G53ELC

Sample


C# proxy class, generated by WSDL.exe

[System.Web.Services.Protocols.

SoapDocumentMethodAttribute(“http://tempuri.org/Add“)]


public int Add(int a, int b) {


object[] results =


this.Invoke(“Add“, new object[] {a, b});


return (int)(results[0]);

}


...


public System.IAsyncResult BeginAdd(...


public int EndAdd(...

G53ELC

Building a Web Service


Create your own
MathService


.asmx


Implement class MathService and Web
methods


Create WSDL file (MathService.wsdl)


Request to MathService.asmx


Generate C# proxy class (MathService.cs)


WebServiceUtil.exe


Generate Assembly (MathService.dll)


C# compiler “csc”

G53ELC

Consuming a Web Service


Implement MathService client
(MathServiceClient.aspx)


ASP.NET UI


Operands


Text box


Methods


Buttons


Result


Label


Event Handler


OnServerClick

G53ELC

Using .Net Webforms

G53ELC

C# Language


Combines the power of C++ with simplicity of Visual Basic


Looks a lot like Java, with classes defined and declared in the same
code blocks


As in Java, everything is an object, and object orientated


No multiple inheritance


Code managed by the CLR, and the compiler provides warnings


Becoming the dominant language at Microsoft


I am sorry they could not use Java, but C# is an improvement

G53ELC

C# Example


Code samples of C#


using System;


class App {


public static void Main(string[] args) {


Console.WriteLine("Hello World");


}

}



More samples and a tutorial at


http://www.csharp
-
station.com/Tutorial_Lesson1.htm

G53ELC

What About C++?


The core semantics of C++ don’t match
the CLR


Managed C++ can be used to write .NET
Framework applications


It relies on extensions to the standard
language


C++ will be important for non
-
Framework
-
based applications

G53ELC

Application Types: Web Forms



Much Less Coding than traditional methods


VB
-
Style Programming Model (event model


Java style?)


Controls (supporting validation)


some very rich


DataGrid


DataList


Calendar


Sessions Are Safe to Use


Span servers in a web farm


Don’t require cookies


Tracing


Caching


More Events in Global.asax


Begin Request, End Request, Error, etc

G53ELC

Let’s Write a Web Form Then


An ASP.NET form is a text file with the
extension
.aspx


IIS will compile this to a .NET class


You can still use the notation

<%

Some script


%>

G53ELC

A Label Field

<
asp:label

id="Message1"


font
-
size="16" font
-
bold="true"
forecolor
="red"
runat
=server>

This is Message One

</
asp:label
>


G53ELC

A Text Field

<html>

<script language="C#" runat="server">



void EnterBtn_Click(Object Src, EventArgs E) {



Message.Text = "Hi " + Name.Text + "!";

}

</script>

<body>

<form action=“apage.aspx" runat=server>

Please enter your name:

<asp:textbox id="Name" runat=server/>


<asp:button text="Enter" Onclick="EnterBtn_Click" runat=server/>

</form>

</body>

</html>

G53ELC

This Is Beautiful


New Html Tags

<%@ Page Language="C#"%>


<html>

<body>

<form action="intro4.aspx" method="post" runat=server>

Name:


<
asp:textbox id="Name" runat="server"/>


<
asp:button text="Lookup" runat="server"/>


</form>

</center>

</body>

</html>

G53ELC

A Drop
-
down List

<form action=“some.aspx" method="post" runat="server">

Category:


<
asp:dropdownlist id="Category" runat=server>




<
asp:listitem>psychology</asp:listitem>





<
asp:listitem>business</asp:listitem>





<
asp:listitem>popular_comp</asp:listitem>


</
asp:dropdownlist>



<
asp:button text="Lookup" OnClick="SubmitBtn_Click"

runat="server"/>


</form>

G53ELC


How Is User Input Processed?

<script language="C#" runat=server>


void SubmitBtn_Click(Object sender, EventArgs e) {

Message.Text = “You selected: “ +





Category.SelectedItem;

}

</script>


This is tidy as you can put the code together at the top of the
page

G53ELC

Database Access




Filling a Table


Import the required database classes
(ADO.NET)


Create a SqlConnection to thedatabase


Construct a SqlDataAdapter object that contains
your query statement


Populate a DataSet object with the results from
the query



Call the command's Fill() method


G53ELC

Reading Data From a Table

<%@ Import Namespace="System.Data" %>

<%@ Import Namespace="System.Data.SqlClient" %>

<html>

<script language="C#" runat="server">

protected void Page_Load(Object sender, EventArgs e) {

SqlConnection myConnection = new
SqlConnection("server=(local)
\
\
NetSDK;database=pubs;Trusted_Connect
ion=yes");

SqlDataAdapter myCommand = new SqlDataAdapter("select * from
Authors", myConnection);

DataSet ds = new DataSet();

myCommand.Fill(ds, "Authors");
MyDataGrid.DataSource=ds.Tables["Authors"].DefaultView;
MyDataGrid.DataBind();

}

</script>


G53ELC

Displaying the Table

<body>

<ASP:DataGrid


id="MyDataGrid" runat="server" Width="700"

BackColor="#ccccff" BorderColor="black"

ShowFooter="false" CellPadding=3

CellSpacing="0"


Font
-
Name="Verdana" Font
-
Size="8pt"


HeaderStyle
-
BackColor="#aaaadd"

EnableViewState="false"

/>


</body>

</html>

G53ELC

A Comaprison .NET or J2EE?


Which is best?


In what way?


For what purpose?


Performance


Cost


Developer time

G53ELC

Standard Library

Application Platforms Today

GUI
Services

Transaction
Services

Web
Scripting

Data
Access

More


Operating System

Runtime Environment

Browser

Apps

Web Services

Apps

Other

Apps

Local

Apps

G53ELC

.NET Framework Class Library

The .NET Framework

Windows
Forms

Enterprise
Services

ASP.NET

ADO.NET

More

Windows

Common Language Runtime

Browser

Apps

Web Services

Apps

Other

Apps

Local

Apps

G53ELC

Standard Java Packages

The Competition: The Java
Environment

Swing

Enterprise
JavaBeans

JavaServer
Pages

JDBC

More

Windows, Solaris, Linux, others

Java Virtual Machine (VM)

Browser

Apps

Web Services

Apps

Other

Apps

Local

Apps

G53ELC

But!


.NET IS COMPELLING!


It has everything an enterprise architecture
needs


It is fast


It is simpler to use than J2EE to develop


It has features that J2EE does not




eg web forms


It is ahead of the game in my opinion

G53ELC

.Net Needs Less Code

G53ELC

Runtime Statistics


.NET ran 28 times faster that J2EE


Supported 7.6 times more concurrent users


Used ¼ the CPU cycles for the same load


Do not believe these statistics!


Picked to show MS in best possible light


But it .NET is probably more efficient

G53ELC

© 2002 Microsoft Corporation. All rights reserved.

The Downside?

Based on Microsoft Operating Systems and
Products


Windows 2000 Server, SQL Server 2000,
Visual .NET

C# is not C and it is not Java

Managed C++ is not C++

J# is not quite Java either

It all costs a lot of money, no open source…