MSCF/CMU1 More on Web Services Maintaining State Legacy Code Asynchronous Calls.

Slides:



Advertisements
Similar presentations
Session 6 Module 2 Calling a Web Service from an ASP.NET Web Page.
Advertisements

Intesar G Ali IT DepartmentPalestinian Land Authority Web services Prepared by: Intesar Ali IT Department PLA August 2010.
© 2009 Dr. Paul Walcott – The University of the West Indies: Cave Hill CampusDr. Paul Walcott COMP6325 Advanced Web Technologies Dr. Paul Walcott The University.
Presentation 10 SOAP on the Microsoft Platform (.NET)
Java Script Session1 INTRODUCTION.
11 Getting Started with ASP.NET Beginning ASP.NET 4.0 in C# 2010 Chapters 5 and 6.
ASP.Net, web services--- asynchronous and synchronous and AJAX By Thakur Rashmi Singh.
Introduction to Web Services
Windows Communication Foundation and Web Services.
6/11/2015Page 1 Web Services-based Distributed System B. Ramamurthy.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 42 Web Services.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
MSCF/CMU1.NET and XML. 2 From Objects to XML using System; using System.Xml.Serialization; using System.IO; namespace XmlTest { public class Node { private.
XML Web Services ASP.NET. Overview of Web Services (Page 1) Web Service – Part or all of a Web application that is publicly exposed so that other applications.
Chapter 12 Extending Web Applications. ASP.NET 2.0, Third Edition2.
Carnegie Mellon University MSCF1 C#/.NET Basics 2 Some code is from “C# in a Nutshell” and “Programming C#”
INTRODUCTION TO WEB SERVICES CS 795. What is a Web Service ? Web service is a means by which computers talk to each other over the web using HTTP and.
1 Web Services Visual C# 2008 Step by Step Chapter 30.
Web Services February 14 th, Outline Overview of web services Create a web service with MS.Net Requirements for project Phase II.
Tutorial: Introduction to ASP.NET Internet Technologies and Web Application 4 th February 2010.
February 24 th -25 th 2004 Daragh Byrne – EPCC Additional.NET Concepts.
XML Web Services in Visual Studio.NET Peter Ty Developer Evangelist.NET and Developer Group.
Intro to C# Dr. John P. Abraham UTPA. Background required Thorough C++ programming – If you made an A in 1370/1170 you will do fine with some effort.
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
IE 411/511: Visual Programming for Industrial Applications
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Web Services Week 7 Aims: A detailed look at the underlying mechanisms for communication between web services Objectives: SOAP, WSDL, UDDI.
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
.Net and Web Services Security CS795. Web Services A web application Does not have a user interface (as a traditional web application); instead, it exposes.
1.NET Web Forms Web Services © 2002 by Jerry Post.
Web Services BOF This is a proposed new working group coming out of the Grid Computing Environments Research Group, as an outgrowth of their investigations.
Web Services. ASP.NET Web Services  Goals of ASP.NET Web services:  To enable cross-platform, cross- business computing  Great for “service” based.
ADVANCED WEB SERVICES. Three Advanced Web Service Techniques SOAP Extensions Asynchronous calls Custom wire formatting SOAP Extensions Asynchronous calls.
Introducing BPEL Concepts Oracle BPEL Process Manager.
XML Web Service. Overview of XML Web Service ASP.NET XML Web services enable you to remotely access the properties and methods of classes across a network.
Telerik Software Academy Web Services & Cloud.
Introduction to Web Services. Examples Using a Web Service Creating a new Web Service.
Copyright © 2013 Curt Hill SOAP Protocol for exchanging data and Enabling Web Services.
Mixing integer and floating point numbers in an arithmetic operation.
1 Web Services Web and Database Management System.
1 Getting Started with C++. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Visual Studio 2008.
VITALE, CATURANO & COMPANY LTD Microsoft SharePoint Web Part Development Overview VITALE, CATURANO & COMPANY LTD SharePoint Developer Series – Web Part.
Jan 2001C.Watters1 World Wide Web and E-Commerce Client Side Processing.
ASP.NET Web Services.  A unit of managed code installed under IIS that can be remotely invoked using HTTP.
Week Six : Writing Web Services Aims: Creating and Consuming student’s first Web Services Learning Outcomes: Familiarity with VS.NET for creating and consuming.
Module 9: Using XML Web Services in a C# Application.
Chapter 7: Creating and Consuming XML Web Services Understanding XML Web Services Creating XML Web Services Deploying and Discovering XML Web Services.
Understanding Web Applications Lesson 4. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Web Page Development Understand Web.
Web Application Development Introduction. Lesson: Creating Web Forms What is a Web Form? Creating a Web Form with Visual Studio.NET.
ODS – Introduction to Web Services and BPEL Vakgroep Informatietechnologie Web Services & BPEL Design of Distributed Software.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
Intro to Web Services Dr. John P. Abraham UTPA. What are Web Services? Applications execute across multiple computers on a network.  The machine on which.
1 Getting Started with C++ Part 1 Windows. 2 Objective You will be able to create, compile, and run a very simple C++ program on Windows, using Microsoft.
.NET Mobile Application Development XML Web Services.
SOAP, Web Service, WSDL Week 14 Web site:
.Net training In gandhinagar 16/10/2016.
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
Introduction to Web Services Srinath Vasireddy Support Professional Developer Support Microsoft Corporation.
E-commerce customization Petr Vozak, Technical Leader.
January 14 th -15 th 2004 Recap of Day 1 Daragh Byrne – EPCC.
Building C# Applications
Windows Communication Foundation and Web Services
Jim Fawcett CSE681 – SW Modeling & Analysis Spring 2005
Windows Communication Foundation and Web Services
Quick Start Guide for Visual Studio 2010
Introduction to C# AKEEL AHMED.
Web Services Introduction
Chapter 42 Web Services.
A Little Bit of Active Server Pages (ASP)
Presentation transcript:

MSCF/CMU1 More on Web Services Maintaining State Legacy Code Asynchronous Calls

MSCF/CMU2 State Management Web Service objects are single call objects The object is created and destroyed on each visit Client Activated objects hold state associated with each client How can we do the same with Web Services? Use an Http Session object

MSCF/CMU3 State Management Example Suppose we need a web service object to store a person’s name. The name is to be available over many visits from the same client. More than one client can use the service at the same time.

MSCF/CMU4 Step by step 1.Write the remote object that uses a session object 2.Compile to a.dll and store in a directory named bin 3.Write a.asmx file and store it in the directory immediately above bin 4.Build a virtual directory named PersonName and point it at the directory immediately above bin

MSCF/CMU5 Step by step 5.Visit 6.Click the.asmx file 7.Experiment with the service 8.Download the WSDL document 9.Run wsdl and generate a C# proxy 10.Compile the proxy to a.dll 11.Write a client with cookies enabled 12.Compile with csc –r:theProxy.dll MyClient.cs

MSCF/CMU6 The Web Service using System; using System.Runtime.Remoting.Lifetime; using System.Web.Services; namespace SessionDemo { public class PersonName : System.Web.Services.WebService { [WebMethod(EnableSession=true)] public void setName(String n) { // write the name to the Session object Session["PersonName"] = n; }

MSCF/CMU7 [WebMethod(EnableSession=true)] public String getName() { // read from the session object String n = (String)Session["PersonName"]; return n; }

MSCF/CMU8 PersonName.asmx WebService Language="c#" Class="SessionDemo.PersonName" CodeBehind="PersonName.cs" %> The pointer to the.cs file is misleading. This is used by Visual Studio to switch between views. We are not using Visual Studio here.

MSCF/CMU9 The Client using System; public class PersonNameClient { static void Main(string[] args) { Console.WriteLine("Visit PersonName p = new PersonName(); p.CookieContainer = new System.Net.CookieContainer();

MSCF/CMU10 // make 2000 visits for(int k = 0; k < 2000; k++) { p.setName(""+k); String s = p.getName(); Console.WriteLine("Visit #" + k + " " + s); } } Test by running the client twice, at the same time and from two different DOS screens.

MSCF/CMU11 Web Services & Legacy Code Many web services will be developed from scratch. Many web services will want to make use of existing code. Existing code is typically “unmanaged”. In this demonstration we will use Visual Studio.NET to create a web service from managed legacy code. The example will use the genetic algorithm project from the previous course.

MSCF/CMU12 C++ As A Web Service Run Visual Studio.NET Select New Project New Project Type = Visual C++ Template = Managed C++ web service Enter a file and directory name Look over the Readme.txt file and the directory structure

MSCF/CMU13 Files Created (From Readme.txt) ACPlusPlusExample.vcproj -- main project file for VC++ projects -- holds information about the platforms, configurations, and project features selected with the Application Wizard.

MSCF/CMU14 ACPlusPlusExample.cpp This is the main web source file. The default is a “hello world” application. In this demo, we’ll write some C++ code to this file.

MSCF/CMU15 ACPlusPlusExample.h -- This header file contains the declarations of the Web Service. The default file contains a function prototype for the hello world web service. -- We’ll add new prototypes (method signatures) to this file. AssemblyInfo.cpp -- Contains custom attributes for modifying assembly metadata.

MSCF/CMU16 ACPlusPlusExample.vsdisco -- discovery file for your web service. -- through the discovery process Web Service clients learn that a Web Service exists, what its capabilities are, and how to properly interact with it. -- an XML document that contains links to other resources that describe the Web Service.

MSCF/CMU17 Web.Config -- This file allows you to override the default configuration settings for your service. An.asmx file -- created as a pointer to this web application.

MSCF/CMU18 Edit the C++ code Select build Select Run icon View the service in a browser On the client side Run wsdl.exe to create a proxy wsdl -o:Proxy.cs Write a client that uses the proxy

MSCF/CMU19 A Client of the Genetic Algorithm using System; public class CallGeneticWebService { public static void Main(string[] args) { double[] values = { 6.5, 1.0, 0.0, 2.0, 7.3, 1.1, 0.0, 2.0, 8.5, 1.15, 1.0, 2.0, 8.7, 1.4, 0.0, 3.0, 9.8, 1.7, 1.0, 3.0, 10.5, 1.8, 1.0, 4.0, 9.5, 1.9, 0.0, 3.0, 12.5, 1.9, 1.0, 4.0, 12.5, 2.1, 2.0, 4.0, 13.7, 2.1, 2.0, 4.0, 15.0, 2.3, 2.0, 4.0 };

MSCF/CMU20 Class1 p = new Class1(); string result = p.GeneticAlgorithm(11,3,values); Console.WriteLine(result); } This will not work without a proxy class generated from the web service WSDL document.

MSCF/CMU21 MyClient Our data set is

MSCF/CMU22 Our function is = (( (( x1) + (x2 + (( (((x0 + x2) - ( * (( (((((x0 + x0) - x1) / x2) + x1) + x2)) + (((( x1) + (x0 + (( ) + x0))) + x0) – ( * x0))))) / x2)) + x0)))) + x0)

MSCF/CMU23 Web Service Browser Test and Learn WSDL = Web Services Description Language WSDL.EXE Proxy code to handle communications and marshalling Of parameters

MSCF/CMU24 Genetic Client Proxy C++ Web Service SOAP

MSCF/CMU25 Asynchronous Web Service The generated proxy contains code for asynchronous calls. We make a call to the service and then continue executing We have two ways to get the result: (1) Provide a callback method (2) Call a specific method to get the result

MSCF/CMU26 A Second Client // AsyncGeneticlient/MyClient.cs // Each method in the proxy has a BeginXXX and EndXXX // where XXX is the name of the web service method. using System; using System.Threading; public class CallGeneticWebServiceAsync { class MyStateObject { public AutoResetEvent Event = new AutoResetEvent(false); public Class1 calc = new Class1(); }

MSCF/CMU27 public static void MyFinishProc(IAsyncResult iar) { MyStateObject o = (MyStateObject) iar.AsyncState; string result = o.calc.EndGeneticAlgorithm(iar); Console.WriteLine(result); o.Event.Set(); // tell the main thread }

MSCF/CMU28 public static void Main(string[] args) { double[] values = { 6.5, 1.0, 0.0, 2.0, 7.3, 1.1, 0.0, 2.0, 8.5, 1.15, 1.0, 2.0, 8.7, 1.4, 0.0, 3.0, 9.8, 1.7, 1.0, 3.0, 10.5, 1.8, 1.0, 4.0, 9.5, 1.9, 0.0, 3.0, 12.5, 1.9, 1.0, 4.0, 12.5, 2.1, 2.0, 4.0, 13.7, 2.1, 2.0, 4.0, 15.0, 2.3, 2.0, 4.0 };

MSCF/CMU29 MyStateObject stateObject = new MyStateObject(); IAsyncResult iar = stateObject.calc.BeginGeneticAlgorithm(11, 3, values, new AsyncCallback(MyFinishProc), stateObject); Console.WriteLine("Waiting for call back to complete"); stateObject.Event.WaitOne(); }

MSCF/CMU30 AsyncGeneticClient>MyClient Waiting for call back to complete Our data set is Our function is = ((((x0 + x0) + x0) + (x1 + ( * (((((((((x ) + x0) + x1) / (x0 + x0)) + x0) ) + x0) + (x1 + ( * ((((((x ) + x2) + (x1 + ( * (((x ) + x1) / (x0 + x0))))) ) + ((x ) + x0)) / (x0 + x0))))) / (x0 + x0))))) + x2)