Document

advertisement
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Software Architecture
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
INDEX
Sr
No.
Title
01.
To develop an architecture document for a project “Course
Registration”. Here the Use case views of the architecture are
described
02.
To develop an architecture document for a project “Course
Registration”. Here the process views of the architecture are
described
03.
To develop an architecture document for a project “Course
Registration”. Here the Deployment views of the architecture are
described
04.
To develop a CORBA component as a web service for finding
weather forecast information
05.
To develop a CORBA component as a web service for finding Stock
Market Exchange information
06.
To develop web service named “Hello World” using ASP.NET for
displaying ” Hello World”
07.
08.
Page
No.
Date
Sign
To use ASP.NET to create Web Service for reversing a string using
external .NET assembly and the client using HTTP- POST to call the
Web service.
To use ASP.NET to create Web Service for adding two numbers
and the client using XMLHTTP to call the Web service via SOAP
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Practical No. 04
Problem Statement: To develop a CORBA component as a web service for finding weather
forecast information.
Description:
A CORBA component is created which can be reused in several applications
wherever there is a requirement for finding the weather information of a particular region.
The steps to be followed to implement this CORBA program are as follows.
Step 1: save all the programs
>path=c:\j2sdk1.4.1_01\bin
in
C:\j2sdk1.4.1_01\bin
or
set
path
as
Step 2: open one command prompt
Step 3: C:\J2SDK1~1.1_0\bin>set classpath=;.
Step 4: C:\J2SDK1~1.1_0\bin>idlj -oldImplBase -fall Weather.idl
Folder WeatherForecast is created
Step 5: C:\J2SDK1~1.1_0\bin>set classpath=%classpath%;.
Step 6: C:\J2SDK1~1.1_0\bin>javac WeatherForecastImpl.java
Step 7: C:\J2SDK1~1.1_0\bin>javac WeatherForecastServer.java
Step 8: C:\J2SDK1~1.1_0\bin>tnameserv
Initial Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e
67436f
6e746578744578743a312e300000000000010000000000000084000102000000000f3133
322e3134
372e3137312e333300000384000000000035afabcb0000000020a209fcb60000000100000
0000000
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
00010000000d544e616d65536572766963650000000000000004000000000a0000000000
00010000
000100000020000000000001000100000002050100010001002000010109000000010001
0100
TransientNameServer: setting port for initial object references to: 900
Ready.
Folder orb.db is created
Step 9: open another command prompt2
Step 10: C:\j2sdk1.4.1_01\bin>set classpath=;.
Step 11: C:\j2sdk1.4.1_01\bin>java WeatherForecastServer
The WeatherForecast Server is up and ready..
Step 12: open another command prompt3
Step 13: C:\J2SDK1~1.1_0\bin>set classpath=;.
Step 14: C:\J2SDK1~1.1_0\bin>javac WeatherForecastClient.java
Step 15: C:\J2SDK1~1.1_0\bin>java WeatherForecastClient
Enter the Celsius
36.9
Temperature of my city in Fahrenheit is 98.42
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Program :
Weather.idl :
module WeatherForecast{
interface Weather{
double get_celsius(in string symbol);
};
};
WeatherForecastImpl.java :
import org.omg.CORBA.*;
import WeatherForecast.*;
public class WeatherForecastImpl extends _WeatherImplBase {
public double get_celsius(String symbol) {
double celsius = Double.parseDouble(symbol);
double fahrenheit = 1.8 * celsius+32;
return fahrenheit;
}
public WeatherForecastImpl()
{super();}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
WeatherForecastClient.java :
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import WeatherForecast.*;
import java.io.*;
public class WeatherForecastClient{
public static void main(String args[]) {
try{
ORB orb=ORB.init(args,null);
NamingContext
ncRef
NamingContextHelper.narrow(orb.resolve_initial_references("NameService"));
=
NameComponent path[]={new NameComponent("FORECAST","")};
Weather weather = WeatherHelper.narrow(ncRef.resolve(path));
System.out.println("Enter the celsius");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String cel = br.readLine();
System.out.println("Temperature
weather.get_celsius(cel));
of
my
city
in
Fahrenheit
is
}
catch(Exception e){ e.printStackTrace(); }
}
}
Page No-
"
+
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
WeatherForecastServer.java :
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import WeatherForecast.*;
public class WeatherForecastServer{
public static void main(String args[]){
try{
ORB orb = ORB.init(args,null);
WeatherForecastImpl weatherForecastImpl = new WeatherForecastImpl();
orb.connect(weatherForecastImpl);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("FORECAST","");
NameComponent path[]={nc};
ncRef.rebind(path,weatherForecastImpl);
System.out.println("The WeatherForecast Server is up and ready..");
Thread.currentThread().join();
}
catch(Exception e) {e.printStackTrace();}
}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Practical No.05
Problem Statement: To develop a CORBA component as a web service for finding Stock
Market Exchange information.
Description:
A CORBA component is created which can be reused in several applications
wherever there is a requirement for finding the Stock information of a particular Exchange
of a particular company.
The steps to be followed to implement this CORBA program are as follows:
Step 1: save all the programs
>path=c:\j2sdk1.4.1_01\bin
in
C:\j2sdk1.4.1_01\bin
or
set
path
as
Step 2: Open Command Prompt
Step 3:
C:\J2SDK1~1.1_0\bin>set classpath=;.
Step 4: C:\J2SDK1~1.1_0\bin>idlj -oldimplbase -fall StockMarket.idl
Folder SimpleStocks is created
Step 5: C:\J2SDK1~1.1_0\bin>set classpath=%classpath%;.
Step 6: C:\J2SDK1~1.1_0\bin>javac StockMarketImpl.java
Step 7: C:\J2SDK1~1.1_0\bin>javac StockMarketServer.java
Step 8: C:\J2SDK1~1.1_0\bin>tnameserv
Initial Naming Context:
IOR:000000000000002b49444c3a6f6d672e6f72672f436f734e616d696e672f4e616d696e
67436f
6e746578744578743a312e300000000000010000000000000084000102000000000f3133
322e3134
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
372e3137312e333300000384000000000035afabcb0000000020a1e5b8b70000000100000
0000000
00010000000d544e616d65536572766963650000000000000004000000000a0000000000
00010000
000100000020000000000001000100000002050100010001002000010109000000010001
0100
TransientNameServer: setting port for initial object references to: 900
Ready.
Folder orb.db is created
Step 9: open another command prompt
Step 10: C:\j2sdk1.4.1_01\bin>set classpath=;.
Step 11: C:\j2sdk1.4.1_01\bin>java StockMarketServer
The StockMarket Server is up and ready..
Step 12: open third command prompt
Step 13: C:\J2SDK1~1.1_0\bin>set classpath=;.
Step 14: C:\J2SDK1~1.1_0\bin>javac StockMarketClient.java
Step 15: C:\J2SDK1~1.1_0\bin>java StockMarketClient
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Program :
StockMarket.idl :
module SimpleStocks{
interface StockMarket{
float get_price(in string symbol);
};
};
StockMarketImpl.java :
import org.omg.CORBA.*;
import SimpleStocks.*;
public class StockMarketImpl extends _StockMarketImplBase {
public float get_price(String symbol) {
float price=0;
for(int i=0;i<symbol.length();i++) {
price+=(int)symbol.charAt(i);
}
price/=5;
return price;
}
public StockMarketImpl() {super();}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
StockMarketServer.java :
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleStocks.*;
public class StockMarketServer{
public static void main(String args[]){
try{
ORB orb = ORB.init(args,null);
StockMarketImpl stockMarketImpl = new StockMarketImpl();
orb.connect(stockMarketImpl);
org.omg.CORBA.Object
orb.resolve_initial_references("NameService");
objRef
=
NamingContext ncRef = NamingContextHelper.narrow(objRef);
NameComponent nc=new NameComponent("NASDAQ","");
NameComponent path[]={nc};
ncRef.rebind(path,stockMarketImpl);
System.out.println("The StockMarket Server is up and ready..");
Thread.currentThread().join();
}
catch(Exception e){e.printStackTrace();}
}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
StockMarketClient.java :
import org.omg.CORBA.*;
import org.omg.CosNaming.*;
import SimpleStocks.*;
public class StockMarketClient{
public static void main(String args[]) {
try{
ORB orb=ORB.init(args,null);
NamingContext ncRef = NamingContextHelper.narrow(orb.resolve_initial_references
("NameService"));
NameComponent path[]={new NameComponent("NASDAQ","")};
StockMarket market = StockMarketHelper.narrow(ncRef.resolve(path));
System.out.println("Price
of
MY
market.get_price("MY_COMPANY"));
COMPANY
is
$"
}
catch(Exception e){ e.printStackTrace(); }
}
}
Page No-
+
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Practical No. 06
Aim: To develop web service named “Hello World” using ASP.NET for displaying ” Hello World”
Description : Create a C# version of the HelloWorld web service and save the file to the web server
under the c:\inetpub\wwwroot folder with the name HelloWorld.asmx.
Program :
HelloWorld: C# web service
<%@ WebService Language="C#"
Class="ProgWS.Ch02.HelloWorldService" %>
using System.Web.Services;
namespace ProgWS.Ch02
{
public class HelloWorldService: WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Creating a C# web service project
To create a new web service, fire up Visual Studio .NET and either select the New Project button on
the default Start Page or click File New Project on the main Visual Studio .NET menu bar. The
Visual Studio project model is the same as earlier versions, in that a file can be part of a project, and
a project part of a solution. A solution is the outermost container, containing zero or more projects.
After selecting an option to create a new project, you'll see the screen in the following Figure
Creating a new Visual Studio project
Under Visual C# Projects, one template option creates an ASP.NET web service. In addition to
selecting a project language and template, specify a project name and location. The location for the
HelloWorldService should be the URL of the IIS web server configured to work with FrontPage
Extensions (e.g., http://localhost) The project name is "HelloWorldService."
The IDE will create a virtual folder under IIS with the same name as the project name
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Exploring the solution and project
The contents of the new project are displayed in the Solution Explorer window, which should appear
on the right side of the VS.NET IDE, as shown in Figure.
Figure The Visual Studio .NET Solution Explorer
Visual Studio .NET also automatically creates several assembly references and files, which are also
displayed in the Solution Explorer, as shown in Figure . Here, VS.NET has included assembly
references to the System, System.Data, System.Web, System.Web.Services, and System.XML
namespaces.
Figure :Displaying all files in VS.NET Solution Explorer
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
The five other files that appear in the Figure above are AssemblyInfo.cs, Global.asax,
HelloWorldService.vsdisco, Service1.asmx, and Web.config. The only file needed to create the web
service is the .asmx file,
Open the page Service1.asmx by double-clicking it, Visual Studio .NET displays a blank design page
in its main window. Rename the Service1.asmx file to HelloWorldService.asmx.
using System;
using System.Web;
using System.Web.Services;
namespace ProgWS.Ch02
{
public class HelloWorldService : System.Web.Services.WebService
{
public HelloWorldService() {}
// WEB SERVICE EXAMPLE
// The HelloWorld() example service returns the string Hello World
// To build, uncomment the following lines, then save and build the project
// To test this web service, press F5
//[WebMethod]
//public string HelloWorld()
//{
//return "Hello World";
//}
}
}
This code should look familiar since it is nearly identical to the code shown in Example 2-1. All you
need to do to make it look like the earlier example is to remove the comments in front of the
HelloWorld() method and [WebMethod] attribute.
Notice, however, that the WebService directive that was present in the inline code example is
missing:
<%@ WebService Language="C#" Class="ProgWS.Ch02.HelloWorldService" %>
Recall that this directive is required to tell the compiler which class file to use as the entry point for
the web service. So where is it? When you wrote the inline code example, you included both the
directive and the source code for the HelloWorld class in the same file. By contrast, when Visual
Studio .NET creates web service code, it separates the WebService directive and the source code
using an approach known to ASP.NET developers as code-behind.
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Practical No. 07
Aim : To use ASP.NET to create Web Service for reversing a string using external .NET assembly
and the client using HTTP- POST to call the Web service.
Description :
Step 1: Create the ASP.NET Web Service Source File named MyWebService2.asmx
<%@ WebService Language="C#" class="MyWebService.MyStringReverse, MyWebServiceImpl"
%>
The file MyWebService2.asmx is referencing another .NET Assembly MyWebServiceImpl which is
located under the /bin ASP.NET Application sub-folder (note that the default location for Assemblies
in ASP.NET is /bin sub-folder under each ASP.NET Applications). The source of .NET Assembly
MyWebServiceImpl is written by C#
MyWebServiceImpl.cs :
namespace MyWebService
{
using System ;
using System.Web.Services ;
public class MyStringReverse: WebService
{
[WebMethod(Description="Reverse String")]
public String ReverseString ( String InString )
{
// Check null String
if ( InString == null ) return null ;
Int32 intSize = InString.Length ;
char[] arrayInString = InString.ToCharArray() ;
char[] arrayOutString = new char[intSize] ;
for (Int32 i = 0 ; i < intSize ; ++i)
arrayOutString[i] = arrayInString[intSize-i-1] ;
return new String(arrayOutString) ;
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
}
}
}
To create the Assembly, use the following command:
C:\>CSC /t:library /out:bin/MyWebServiceImpl.dll MyWebServiceImpl.cs
Step 2: Create the ASP.NET Web Service Clients
Client use HTTP-POST Method to consume the web services
TestWebService.aspx
<html>
<body>
<form action="http://localhost/ASP.NET/MyWebService2.asmx/ReverseString" method="POST">
<input name="a"></input>
<input type="submit" value="Enter"> </input>
</form>
</body>
</html>
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Practical No.08
Aim : To use ASP.NET to create Web Service for adding two numbers and the client using
XMLHTTP to call the Web service via SOAP
Description :
Step 1: Create the ASP.NET Web Service Source File
MyWebService.asmx
<%@ WebService Language="C#" class="MyClass" %>
using System.Web.Services ;
public class MyClass
{
[WebMethod()]
public int Add ( int a, int b)
{
return a + b ;
}
}
Page No-
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
Step 2: Create the ASP.NET Web Service Clients
Client use XMLHTTP to call Web service via SOAP
create an ASP client file named TestWebServiceByXML.asp
<html>
<body>
<script language="jscript">
function btn_click (a, b)
{
var xmlObj = new ActiveXObject("Msxml2.DOMDocument") ;
var sXml = "<?xml version=\"1.0\" ?>" ;
sXml += "<soap:Envelope "
sXml += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " ;
sXml += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " ;
sXml += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" ;
sXml += "<soap:Body>" ;
sXml += "<Add xmlns=\"http://tempuri.org/\">" ;
sXml = sXml + "<a>" + a.value + "</a>" ;
sXml = sXml + "<b>" + b.value + "</b>" ;
sXml += "</Add></soap:Body></soap:Envelope>"
// Try to parse the XML string into DOM object
xmlObj.loadXML(sXml) ;
//To see the validated XML string is well-formed
XmlRequest.innerText = xmlObj.xml ;
var xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP") ;
xmlHTTP.Open ( "Post", "http://localhost/ASP.NET/MyWebService.asmx", false) ;
xmlHTTP.setRequestHeader("SOAPAction", "http://tempuri.org/Add") ;
xmlHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8" ) ;
xmlHTTP.Send(xmlObj.xml) ;
MyResult.innerText = xmlHTTP.responseText ;
var xmlResponse = xmlHTTP.responseXML ;
answer.innerText
xmlResponse.selectSingleNode("soap:Envelope/soap:Body/AddResponse/AddResult").text ;
}
</script>
<form>
Page No-
=
Software Architecture And Virtual Reality& Virtual Environment (M.Sc. (IT) Part-II)
<p>Please input a:<input id="a" name="a"></input></p>
<p>Please input b:<input id="b" name="b"></input></p>
<p>
<input type="button" id="btn" value="Enter"
onclick="jscript:btn_click(a, b)"></input>
</p>
<p>Answer is <span id="answer"></span></p>
<hr></hr>
<p>Request:</p>
<span id="XmlRequest"></span>
<p>Response:</p>
<span id="MyResult"></span>
</form>
</body>
</html>
Step 3: To test the webservice
Install Microsoft XML Parser 3.0 in the client machine that gives the XMLHTTP and DOM COM objects to
test the application.
Page No-
Download