Вы находитесь на странице: 1из 24

EX.NO: 1 DEVELOPING COMPONENTS USING .

NET COMPONENT TECHNOLOGY

AIM: To Create components for order processing using .NET component technology.

What Is a .NET Component? A component is a special type of executable built from a .NET project. After compilation the component is typically referenced by applications needing the services provided by the component. In many .NET Web environments, components run on the Web server and provide data and other services ALGORITHM: Creating a Class Follow these steps to build a simple class module that returns the host computer's date and time: 1. Start Visual Studio .NET and open a new Windows Application project. 2. Ignoring the default Windows Form in the project, on the Project menu, click Add Class to add a new file to the project. 3. Change the name of the generated Public Class from Class1 to ServerTime. 4. Enter the following code to define the ServerTime class. Public Class ServerTime Private mdtTime As DateTime ReadOnly Property TimeStamp() As String Get mdtTime = Now() Return CStr(mdtTime) End Get End Property End Class The private variable named mdtTime is not entirely necessary in this class; you could simply return the current date and time without first assigning it to the mdtTime variable. But, because programming projects so often grow beyond their initial specification, there may be a need in the future to have a module-level variable shared by multiple properties and/or methods within the ServerTime class. Next, use the Windows Form that was automatically created in the new project to test the functioning of the ServerTime class. Follow these steps to create an object from the ServerTime class and use it in the Windows Form:

1. Rename the form from Form1 to frmConsumer to emphasize its role as the consumer of the class module. 2. Add a TextBox to the Windows Form and name it txtServerTime. 3. Delete the string in the Text property so that it is blank. 4. Add a button to the Windows Form and name it btnGetServerTime. 5. Set the Text property of this button to Get Server Time. 6. Double-click the button to add the following code behind the Windows Form (continuation characters have been added to the event procedure's declaration for clarity): Private Sub btnGetServerTime_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnGetServerTime.Click Dim st As ServerTime st = New ServerTime() txtServerTime.Text = st.TimeStamp End Sub Because the ServerTime class is included in this project's assembly, there is no need to reference it from the consumer form's code module. .NET is able to locate the ServerTime class and instantiate the st object variable from the information in the class. When this code has been added to the button's Click event procedure, the current date and time are written into txtServerTime each time the button is clicked. Test out this application to see if you typed everything in correctly. 1. Press F5 to run this application. 2. Click Get Server Time and, in the text box, you should see a Date and Time. Creating the Component In the previous section, you created a simple class module that returns the current date and time, and tested the class module in a .NET Windows Form. Follow these steps to build a .NET DLL component from the code you used in the previous class module example: 1. Start Visual Studio .NET and open a new Class Library project. In the New Project dialog box, name the project ServerTime. 2. Change the name of the class from Class1 to ServerTime. 3. Either copy the code out of the ServerTime class module you created in the previous example into the new ServerTime class module, or enter the following code into the new ServerTime class module: Public Class ServerTime Private mdtTime As DateTime ReadOnly Property TimeStamp() As String Get mdtTime = Now() Return CStr(mdtTime) End Get

End Property End Class You will now compile this ServerTimer class as a DLL by clicking Build on the Debug menu or by using the Ctrl+Shift+B keystroke combination. The DLL that results from the build command is placed into the \bin directory immediately below your .NET project directory. By default, the DLL has the same name as your component project. For instance, if you named the project TimeStamp in the New Project dialog, the DLL produced by your project will be named TimeStamp.DLL. This name is also the default Namespace name for the classes contained within the project. If you followed the steps in this document, your project is named ServerTime. You also named the only class within the project ServerTime. Therefore, your DLL name will be ServerTime.DLL and consumer applications of this DLL will reference ServerTime.ServerTime to create an object of this class. Create a DLL Consumer Application Once the DLL project has been compiled, its services are available to any Windows Form or WebForm .NET application. In this section, you will build a simple Windows Form consumer application that uses the ServerTime class to retrieve the computer's date and time.
Create a DLL Consumer Application

Once the DLL project has been compiled, its services are available to any Windows Form or WebForm .NET application. In this section, you will build a simple Windows Form consumer application that uses the ServerTime class to retrieve the computer's date and time. Follow these steps to create the consumer application: 1. Start Visual Studio .NET, select Windows Application as the new project type, and name the project DLLConsumer1. 2. Set the Name property of the default Windows Form to frmConsumer. 3. Add a button control to the default Windows Form and name it btnGetServerTime. 4. Add a TextBox to the form and name it txtServerTime. You need to set a reference to the ServerTime DLL so that this form will be able to consume the components services. Do this by following the steps below.
1. To open the Add Reference dialog box as shown in Figure 1, on the Project menu, click

Add Reference.

The .NET tab in the Add Reference dialog box

2. Click the Projects tab and then click Browse to locate the component DLL built in the
preceding section .

Selecting a DLL reference

3. Select the ServerTime.DLL file, click Open, and then click OK.

The Solution Explorer, as shown in Figure 3, now shows the ServerTime component added as a reference in your application. What this means is that all of the classes, along with their properties, methods, and events, are now available to your consumer application.

Solution Explorer showing all current references Add the following code to btnGetServerTime's Click event:

Private Sub btnGetServerTime_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnGetServerTime.Click Dim st As ServerTime st = New ServerTime() txtServerTime.Text = st.TimeStamp End Sub

SAMPLE OUTPUT: You should see the message

Successful installation of legacy COM component message RESULT: Thus program for developing order processing using .NET component technology.

EX.NO: 2 DEVELOPING COMPONENTS USING EJB COMPONENT TECHNOLOGY


AIM: To perform arithmetic operation using EJB component technology.

ALGORITHM:

1. Go to file -newproject enterprise - enterpriseapplication and then give next 2. Now give the project name ,location and select server as GlashFishv2 and version JavaEE5 3. And give finish.Now project opens and hierarchy is shown at left side of the window. 4. Next in hierarchy click on EnterpriceApplication1-ejb and then in that right click on SourcePackage new-SessionBean, 5. Now in sessionbean window give sessionbean name and package name and select stateless and click on remote and remove ckeck mark in local then click on finish. 6. Now in coding window add the business method. 7. Now in project hierarchy(left side) click on Enterpriseapplication-client1-ejp and then click on sourcepackage-Enterpriceapplication1-double click on Main.java. 8. Now in coding window import the package by right clicking below the import statement select enterprise resourse -call enterprisebean-ok. 9. Now do the coding in main class to call the function using bean. 10. Save the project. 11. Build the main project. 12. Run the main project.

SAMPLE OUTPUT: 1.Addition 2.subtraction 3.multiplication 4.division

enter ur choice:1 enter value of a:5 enter value of b:5 addition is:10 1.Addition 2.subtraction 3.multiplication 4.division enter ur choice:2 enter value of a:5 enter value of b:5 subtraction is:0 1.Addition 2.subtraction 3.multiplication 4.division enter ur choice:3 enter value of a:5 enter value of b:5 multiplication is:25 1.Addition 2.subtraction 3.multiplication 4.division enter ur choice:4 enter value of a:5 enter value of b:5 division is:1

RESULT:

Thus Program to perform Arithmetic operation was performed suceessfully using EJB component Technology.

EX.NO: 3
AIM:

INVOKING OF .NET COMPONENTS AS WEB SERVICES

To invoke .NET component as web services. ALGORITHM:


The various steps that are involved in creating a Web Service Component using C# and the .NET Framework are as follows 1. Create a Visual C# - ASP.NET Web Service project 2. Develop the OIDServer.asmx file and the OIDServer.asmx.cs class file 3. Modify the generated AssemblyInfo.cs to add the right assembly information 4. Build the Project Files Create a new Visual C# ASP.NET Web Service project.

To Create a Web service 1. Open Visual Web Developer. 2. On the File menu, click New Web Site. The New Web Site dialog box appears. 3. 4. 5. 6. 7. Under Visual Studio installed templates, click ASP.NET Web Service. Click Browse. Click Local IIS. Click Default Web Site. Click Create New Web Application. Visual Web Developer creates a new IIS Web application. 8. Type the name TemperatureWebService. 9. Click Open. The New Web Site dialog box appears, with the name of the new Web site in the rightmost Location list. The location includes the protocol (http://) and location (localhost). This indicates that you are working with a local IIS Web site. 10. In the Language list, click the programming language that you prefer to work in. The programming language that you choose will be the default for the Web site. However, you can use more than one language in the same Web application by creating pages and components in different programming languages. For more information about how to create components using different languages. Click OK. Visual Web Developer creates the new Web service and opens a new class named Service, which is the default Web service. However, in the following procedure you will create a new Web service with a specified name and you will not use the Service class. 1. Close the Service class. Adding the Web Service as a Component The Web service is a component that you can reference in your application. Therefore, you must create a reference to it. To create a reference to the Web service
1. On the Web Site menu, click Add Web Reference.

The Add Web Reference dialog box appears, as shown in the following screen shot. Add Web Reference dialog box

2. In the URL list, enter the following URL for the Web service, and then click Go:

http://localhost/TemperatureWebService/Convert.asmx When Visual Web Developer finds the Web service, information about the Web service appears in the Add Web References dialog box. 3. Click one of the method links. The test page for the method appears.
4. Click Add Reference.

Visual Web Developer creates an App_WebReferences folder and adds a folder to it for the new Web reference. By default, Web references are assigned a namespace corresponding to their server name (in this case, localhost). Make a note of the name for the Web reference namespace. In the folder, Visual Web Developer adds a .wsdl file that references the Web service. It also adds supporting files, such as discovery (.disco and .discomap) files, that include information about where the Web service is located.

SAMPLE OUTPUT:
Temperature conversion page

RESULT:

Thus program to invoke .NET component as web services was implemented successfully.

EX.NO: 4
AIM:

INVOKING OF EJB COMPONENTS AS WEB SERVICES

To invoke EJB component as web services. ALGORITHM: EJB 3.0 does specify additional rules for the bean implementation class: It must be declared public and must have a default constructor that doesn't take any arguments. It must not be final or abstract and must be a top-level class. It must not define a finalize() method.

Packaging the Web Service

A web service based on the EJB programming model needs to be packaged as a JAR file. Using the @WebService annotation, you only need to package the service implementation bean class (with its dependent classes, if any) and the service endpoint interface class (if explicitly provided). endpoint/Calculator.class endpoint/jaxws/Add.class endpoint/jaxws/AddResponse.class

Writing the Client After you deploy the web service, you can access it from a client program. A client uses a @WebServiceRef annotation to declare a reference to an EJB 3.0-based web service. The @WebServiceRef annotation is in the javax.xml.ws package, and is specified in JAX-WS 2.0 Web Services Metadata for the Java Platform, JSR 181. If you examine the source code JAXWSClient, the client program used in this tip (you can find the source code for JAXWSClient in the client directory of the installed sample package), you'll notice the following: @WebServiceRef(wsdlLocation= "http://localhost:8080/CalculatorService/Calculator?WSDL") static endpoint.CalculatorService service; Running the Sample Code

A sample package accompanies this tip. It demonstrates the techniques covered in the tip. To install and run the sample:
1. If you haven't already done so, download GlassFish from the GlassFish Community

Downloads page. 2. Set the following environment variables: GLASSFISH_HOME: This should point to where you installed GlassFish (for example C:\Sun\AppServer) ANT_HOME: This should point to where ant is installed. Ant is included in the GlassFish bundle that you downloaded. (In Windows, it's in the lib\ant subdirectory.) JAVA_HOME: This should point to the location of JDK 5.0 on your system. Also, add the ant location to your PATH environment variable. 3. Download the sample package for the tip and extract its contents. You should now see the newly extracted directory as <sample_install_dir>/ttmar2006ejb-ws, where <sample_install_dir> is the directory in which you installed the sample package. For example, if you extracted the contents to C:\ on a Windows machine, then your newly created directory should be at C:\ttmar2006ejb-ws. The ejb-techtip directory below ttmar2006ejb-ws contains the source files and other support file for the sample. 4. Change to the ejb-techtip directory and edit the build.properties files as appropriate. For example, if the admin host is remote, change the value of admin.host from the default (localhost) to the appropriate remote host. 5. Start GlassFish by entering the following command: 6. <GF_install_dir>/bin/asadmin start-domain domain1 where <GF_install_dir> is the directory in which you installed GlassFish. 7. In the ejb-techtip directory, execute the following commands: 8. ant build This creates a build directory, compiles the classes, and puts the compiled classes in the build directory. It also creates an archive directory, creates a JAR file, and puts the JAR file in the archive directory. ant deploy This deploys the JAR file on GlassFish. ant build-client This generates portable artifacts and compiles the client source code.

ant run SAMPLE OUTPUT: 1. [echo] Executing appclient with client class as 2. client.JAXWSClient 3. [exec] Retrieving port from the service 4. endpoint.CalculatorService@159780d 5. [exec] Invoking add operation on the calculator port 6. [exec] Adding : 0 + 10 = 10 7. [exec] Adding : 1 + 10 = 11 8. [exec] Adding : 2 + 10 = 12 9. [exec] Adding : 3 + 10 = 13 10. [exec] Adding : 4 + 10 = 14 11. [exec] Adding : 5 + 10 = 15 12. [exec] Adding : 6 + 10 = 16 13. [exec] Adding : 7 + 10 = 17 14. [exec] Adding : 8 + 10 = 18 15. [exec] Adding : 9 + 10 = 19

RESULT:

Thus program for designing calculator was implemented using EJB component as web services.

EX.NO:5

Develop a Service Orchestration Engine using WS-BPEL and Implement service composition

AIM: To develop a service orchestration engine using WS-BPEL (workflow) and implement service composition. ALGORITHM:
BPEL is used as a server side programming language. This means that companies will often either deploy BPEL as something to serve and track a customer request or they will deploy a BPEL server as a nice easy to use proxy to all their legacy systems. In either case, a common chain of events will be as follows: Web Service client (user) requests something from the server (perhaps via a browser or another server) Client request is received by the BPEL server. Client request is identified as a new request and a new BPEL process is used to serve that client Client continues to interact with the BPEL process, making requests etc, until the interaction is complete BPEL process disappears and client goes about it's business

This automatic creation of BPEL process instances in response to client requests is called 'create on demand'. The TPTP BPEL engine has a different focus. It's primary focus is to act as an execution engine which can be programmed using BPEL. The common chain of events for the TPTP BPEL engine is therefore slightly different:

User writes a BPEL program as a series of steps to carry out User runs BPEL program One single copy of the BPEL program is created and immediately executed The running program logs information via local web services The program finishes and the user can look at the logs

BPEL is an XML programming language. As a programming language it has three basic components:

Programming logic Data types Input/Output (I/O)

BPEL splits these components up in the following way:


Programming logic - BPEL Data types - XSD (XML Schema Definition) Input/Output (I/O) - WSDL (Web Services Description Language)

As a simple example, lets take a Hello World program. XSD will be used to define the types used in the program. It will be used to define a string type which will hold the 'Hello World' string. WSDL will be used to define the web service that will actually print the string for us. BPEL will put all these things together to create the string and print it. SAMPLE OUTPUT:
AIRLINE RESERVATION SYSTEM -------------------------------------------------------------------------------MENU: 1:RESERVATION 2:DISPLAY 3:CANCELLATION 4:EXIT Enter your choice Enter your choice : 1 -------------------------------------------------------------------------------Enter passengers details : Name ABC Address 100,USMANROAD,CH-17 E-Mail ID ABC@YAHOO.CO.IN Telephone no 1111111 Enter the date of travelling : 1

1:Domestic 2:International Enter the mode:1 Enter the plane 1 or 2 or 3 1 PASSWORD 131 -------------------------------------------------------------------------------MENU: 1:RESERVATION 2:DISPLAY 3:CANCELLATION 4:EXIT Enter your choice 2 -------------------------------------------------------------------------------1:Passenger Reports -------------------------------------------------------------------------------RESNO NAME ADDRESS SOURCE DESTINATION 131 ABC 100,USMAN ROAd CHENNAI MUMBAI -------------------------------------------------------------------------------------------------------------------------------------------------------------AIRLINE RESERVATION SYSTEM -------------------------------------------------------------------------------MENU: 1:RESERVATION 2:DISPLAY 3:CANCELLATION 4:EXIT Enter your choice 3 ENTER UR PASSWORD: 131 TICKET CANCELLED ------------------------------------------------------------------------------AIRLINE RESERVATION SYSTEM -------------------------------------------------------------------------------MENU: 1:RESERVATION 2:DISPLAY 3:CANCELLATION 4:EXIT Enter your choice : 4

RESULT: Thus Airline reservation was done through WS-BPEl workflow and implement service composition. EX.NO:6 DEVELOP A J2EE CLIENT TO ACCESS .NET WEB SERVICES AIM: To develop a service orchestration engine using WS-BPEL (workflow) and implement service composition. ALGORITHM: To access a Web service in managed code 1. Create the application from which you want to access a Web service. This application could even be another Web service. 2. Add a Web reference for the Web service with which your application will interact. For instructions, see Adding and Removing Web References. 3. Create an instance of the proxy object in your client code where you want to access the Web service. 4. Access the methods of the Web service as you would any other component. In the example code below, the client application (Application1) is accessing a Web service for which it has a Web reference (Converter) that contains a proxy class (Service1), which has a method (ConvertTemperature) for calling the Web service. The two lines of code in bold represent the code that is necessary to access the Web service. Step 1 Create the Web Service Step 2 Consume the Web Service Source File http://localhost/suppliers.asmx?WSDL

SAMPLE OUTPUT:

RESULT:

Thus program for converting temperature to Fahrenheit and Celsius using J2EE client to access .NET web services was completed successfully. EX.NO:7 DEVELOP A .NET CLIENT TO ACCESS J2EE WEB SERVICES

AIM: To develop a .NET client to access J2EE web services ALGORITHM: Prerequisites Before you begin, supply the following files and information.

The WSDL file or location from which the service endpoint interface and JAX-RPC mapping file will be generated. The location where the generated service endpoint interface and JAX-RPC mapping file will be stored.

How to Assemble a J2EE Web Service Client Use the WebServicesAssembler tool to assemble a service endpoint interface and the J2EE Web service client. Then, edit the deployment descriptor to add Web service access information. The following steps describe these tasks in more detail. 1. Provide the WSDL and the information described in the Prerequisites section as input to the WebServicesAssembler genInterface command. For example: 2. java -jar wsa.jar 3. -genInterface 4. -wsdl HelloService.wsdl 5. -output build -packageName oracle.demo.hello This command line uses HelloService.wsdl to generate HelloInterface in the oracle.demo.hello package. Edit the deployment descriptor of the J2EE component to add a <service-ref> element. This element captures all of the Web service access information. Assemble the client deployment module into an EAR file: 1. Compile all the client files. 2. Copy deployment descriptor files to their appropriate locations. For example, for an EJB, copy the WSDL to META-INF/wsdl/, the JAX-RPC mapping file and the deployment files such as ejb-jar.xml and orion-ejb-jar.xml to META-INF, and so

on. For a description of where files should reside for servlet, EJB, or JSP Web service clients, see "Packaging Structure for Web Service Applications". 3. Package the client deployment module. 1. Deploy the client deployment module. The following steps will deploy an EJB, JSP, or other J2EE client. If you are deploying an application client, skip these steps and continue with "Deploying and Running an Application Client Module". a. Start OC4J. The following is a sample command to start OC4J. b. java -jar oc4j.jar c. d. Deploy the client module into OC4J. The following is a sample deployment command. e. java -jar admin_client.jar deployer:oc4j:<oc4jHost>:<oc4jPort> <adminID> <adminPassword> f. -deploy g. -file .\client\myClient.ear h. -deploymentName myClient i. -bindWebApp default-web-site j. The oc4jHost and oc4jPort variables are the host name and port number of the OC4J server. The adminID and adminPassword are the OC4J server user name and password. The following are sub-switches of the -deploy switch. filepath and filename of the EAR file to deploy. deploymentNameuser-defined application deployment name, used to identify the application within OC4J. bindWebAppspecifies the Web site to which the web application should be bound. This is the Web site that will be used to access the application. 2. Run the EJB or JSP client. If you are running an application client, see "Deploying and Running an Application Client Module". Deploying and Running an Application Client Module The following steps describe how to deploy and run an application client module. Unlike EJB, JSP, or other J2EE clients, you must specify the directory where the generated deploymentcache.jar will be stored. You must also specify the location of the deployment-cache.jar in the run command. 1. Start OC4J. The following is a sample command to start OC4J. 2. java -jar oc4j.jar

3. Deploy the application client module into OC4J. The following is a sample deployment command. 4. java -jar admin_client.jar deployer:oc4j:<oc4jHost>:<oc4jPort> <adminID> <adminPassword> 5. -deploy 6. -file .\client\myAppClient.ear 7. -deploymentName myAppClient 8. -deploymentDirectory C:\home\myDir This command creates a deployment-cache.jar file and stores it in C:\home\myDir. The oc4jHost, oc4jPort, adminID, and adminPassword variables and the file and deploymentName sub-switches of -deploy are described in Step 4b of the previous section. The deploymentDirectory sub-switch indicates the location where OC4J deploys deployment-cache.jar. In this example, OC4J deploys it into C:\home\myDir. If you do not specify this sub-switch, OC4J deploys the application into the OC4J_HOME/application-deployments/ directory. If you supply the empty string (" "), OC4J will always read the deployment configurations from the EAR file each time the application is deployed. 9. Run the client deployment module. For an application client, the location of the deployment-cache.jar must be present in the classpath. The following is a sample run command: 10. java -classpath .:C:\home\myDir\deployment-cache.jar:'oc4jclient.jar' 11. :appclient.jar oracle.myappclient.classname In this sample, it is assumed oracle.myappclient.classname. Ant Task for Generating an Interface The current release provides Ant tasks for Web service development. The following sample code shows how the genInterface command in the preceding example can be rewritten as an Ant task. <oracle:genInterface wsdl="${etc.web1.dir}/HelloService.wsdl" output="build" packageName="oracle.demo.hello" /> Adding J2EE Web Service Client Information to Deployment Descriptors You must edit the J2EE component's deployment descriptor to add information that allows the component to access the Web service endpoint. that appclient.jar contains the class

For an EJB 2.1 Web service client, edit the META-INF/ejb-jar.xml deployment descriptor.

Writing J2EE Web Service Client Code This section describes some of the common code that allows a J2EE component to access a Web service. At runtime, all J2EE Web service clients use a standard JNDI lookup to find Web services. The following steps describe the general pattern for coding a JNDI lookup that could be used within a servlet, EJB, or a JSP. 1. Create the initial JNDI context. 2. Context ic = new InitialContext(); The OC4J container sets up the initial context properties. 3. Locate the service using the lookup method from the initial context. The comp/env/service/MyHelloServiceRef in Example 13-5 provides the service reference. The JNDI call returns a reference to a service object. 4. Service service = (Service) ic.lookup("java:comp/env/service/MyHelloServiceRef"); The client always accesses the service implementation by using a JNDI lookup. This lookup returns a container-managed service reference. This allows the container to intervene and provide the client with additional service functionality, such as logging, security, and management. 5. Get a handle to the service port using the getPort method on the container-managed service object. Cast the return value to the interface type. 6. HelloInterface helloPort = (HelloInterface) service.getPort(portQName, oracle.demo.hello.HelloInterface.class);

SAMPLE OUTPUT:

RESULT: Thus program for consumer counter using .NET client to access J2EE web services was completed successfully.