Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 An Implementation of EIDE in C#.NET Mark T. Sundsten

Similar presentations


Presentation on theme: "1 An Implementation of EIDE in C#.NET Mark T. Sundsten"— Presentation transcript:

1 1 An Implementation of EIDE in C#.NET Mark T. Sundsten

2 2 Overview Technology Review –HTTP, SOAP, SMXP (all open protocols) –EIDE Functions Web Service –What is it? –Web Service Description Language (WSDL) –Web Consumer Conceptual Architecture –Web Service, Web Consumer Walkthroughs –Building an EIDE Web Service –Building an EIDE Web Consumer

3 3 Technology Review HTTP (Hypertext Transport Protocol) –Underlying communication protocol –Enables a Request/Response architecture –Browser accessing a Web Site is a good example SOAP (Simple Object Access Protocol) –Layered on top of HTTP –XML based –Envelope, Header, Body SMXP (Simple Message eXchange Protocol) –Leverages SOAP –The idea is that I am invoking a function on a remote machine rather than sending a message. –Data is communicated via parameters and return values EIDE Functions –logical functions defined to facilitate the exchanging of meter, power system and schedule data. –Examples include PutSchedule, PutScheduleAck, GetSchedule, PutMeter, etc –The EIDE Communications Protocol Document defines these functions in terms of the above open technologies (HTTP, SOAP, SMXP). EIDE Functions SMXP SOAP HTTP

4 4 Web Service An application component accessible via open protocols (like HTTP, XML, SMXP, SOAP) Processes XML messages framed using SOAP Describes its message using XML Schema (XSD) Interface is fully described using WSDL (Web Service Description Language) Web Service SMXP SOAP HTTP

5 5 WSDL (Web Service Description Language) –Standard (developed by W3C -- Ariba, IBM, Microsoft) –Machine consumable format (XML) –Describes details of how to access (required inputs, message format, etc. ) –Describes where to access (target URL, ports, etc.) –Contains a Schema Definition (XSD)

6 6 Web Consumer A Web Consumer is any application that accesses a web service

7 7 Secure transmittal of XML document over Internet (HTTPS/SOAP/X.509 certificates) HTTP Request HTTP Response Web Consumer Conceptual Architecture Web ServiceWeb Consumer De-Serialize from XML Serialize to XML Application Objects Data EIDE Web Service Application Objects Data Start with the concept of an application consuming a web service. Entity A Entity B

8 8 Secure transmittal of XML document over Internet (HTTPS/SOAP/X.509 certificates) GetSchedule GetScheduleResponse Conceptual Architecture EIDE Web ServiceEIDE Web Consumer De-Serialize from XML Serialize to XML EIDE Objects Meter Data Pwr Sys Data Schedules RDBMS CSV files EIDE Web Service EIDE Objects Meter Data Pwr Sys Data Schedules RDBMS Specifically, an EIDE application consuming an EIDE web service. Entity AEntity B

9 9 Conceptual Architecture EIDE Web Service EIDE specifies that an entity can be a consumer, a service, or both. (An entity may send or receive unsolicited messages). GetSchedule GetScheduleResponse EIDE Web Service RDBMS EIDE Web Consumer EIDE Objects RDBMS GetScheduleAsyncReply GetScheduleAsyncReplyResponse EIDE Web Consumer RDBMS EIDE Web Service RDBMS EIDE Objects Entity AEntity B

10 10 F i r e w a l l Conceptual Architecture EIDE Web Service Finally, Integrate with Scheduling/EMS Systems GetSchedule GetScheduleResponse EIDE Web Service RDBMS EIDE Web Consumer EIDE Objects RDBMS GetScheduleAsyncReply GetScheduleAsyncReplyResponse EIDE Web Consumer RDBMS EIDE Web Service RDBMS EIDE Objects Scheduling System/ EMS System Entity AEntity B F i r e w a l l

11 11 Underlying technologies EIDE Web Service Leverage Microsoft IIS –For Listening –Authentication, encryption Microsoft.NET Framework –Serialize/De-serialize XML to/from application objects ADO.NET –For Mapping application objects to/from the RDBMS.

12 12 Build An EIDE Web Service Before you get started, you will need the following products: –Microsoft Visual Studio.NET This is the Integrated Development Environment (IDE) for editing and compiling your C# code. –Microsoft.NET Framework Distributed with newer versions of the OS, available off the WEB. Microsoft Internet Information Server (IIS). Oracle (this walkthrough utilizes Oracle, but you could use SQL Server or Microsoft Access)

13 13 1. Start with the EIDE schema (eide.xsd). Build An EIDE Web Service

14 14 2. Use Microsofts XSD utility to generate C# classes that map to the schema (eide.cs). Build An EIDE Web Service

15 15 Build An EIDE Web Service 3. Start the Microsoft Development Environment.

16 16 Build An EIDE Web Service 4.Load a C# Web Service template From the IDE, Select File New Project to bring up the New project dialog Select the project type, C# project Select the template, ASP.Net Web Service Change the location from e1 to er e1 er Click the OK button

17 17 Build An EIDE Web Service 5.Alter to use meaningful names. In the solution explorer, rename Service1.asmx to EIDEService.asmx Right Click on design area and select view code. In the source code, change the namespace, Class Name, and method name from Service1 to EIDEService

18 18 Build An EIDE Web Service 6.Add the eide definitions (eide.cs) to your C# project. Right click on the EIDEService project in the solution explorer and select Add Add Class For a name, type in eide.cs. Click Open Select the entire contents of the file and replace with the eide.cs that you created earlier using the xsd utility. (A shortcut to the three steps above is to drag the eide.cs file from its folder and drop it on top of the EIDE Service project in the solution explorer).

19 19 Build An EIDE Web Service 7.Define the EIDE Web Method, PutPID View the EIDEService source code by clicking on the EIDEService.asmx.cs tab) Scroll to the bottom and observe the commented out sample web method.

20 20 Build An EIDE Web Service 7.Define the EIDE Web Method, PutPID (cont). Uncomment the entire web method and replace the return type string with a return type of PutPIDResponse Change the method name from HelloWorld() to PutPID() Add two parameter definitions within the parenthesis separated by a comma: MessageInfoType MessageInfo, PIDType PID Instead of returning Hello World return null

21 21 Build An EIDE Web Service 8.Compile and deploy (locally) your stubbed out Web Method. Type Ctrl-Shift-B

22 22 Build An EIDE Web Service 9. Note: You now have now built an accessible web service that other programmers can consume and test against. To illustrate this: Bring up a browser and point it to the following url to see a listing of your Web Methods (you only have one at this point). Service.asmx Service.asmx Click on the ServiceDescription to see the automatically generated WSDL. The WSDL contains the complete specifications for communicating with your Web Service.

23 23 Build An EIDE Web Service 9.(Continued) Click on the PutPID to see examples of the http request that your program expects to receive and the http response that it will return.

24 24 Build An EIDE Web Service 10Design and build a RDBMS table to store the data when it comes in. (This example uses Oracle, although you could just as easily use MS Access or SQL Server.) For purposes of this walkthrough, I am only dealing with the MessageInfo portion of the EIDE data. It is left as an exercise to create tables for storing everything else. The following can be used to create the table in Oracle. create table eide_MessageInfo ( SysGenID Number(10) default 0 NOT NULL,Timestamp Date NOT NULL,Sender VARCHAR(40),Receiver VARCHAR(40),EntityCode VARCHAR(40),ProcessID Number(10) default 0 NOT NULL,DataSet Number(10) default 0 NOT NULL,ListID Number(10) default 0 NOT NULL,ResponseSysGenID Number(10) default 0 NOT NULL,Comments VARCHAR(200),AsyncReplyFlag Number(10) default 0 NOT NULL ); CREATE INDEX eide_MessageInfo$PK ON eide_MessageInfo (SysGenID, Timestamp, Sender);

25 25 Build An EIDE Web Service 11. Setup the ADO.Net C# Data Adapter necessary to access your newly built table. Return to the Microsoft IDE Select the EIDEService.asmx [Design] tab From the View pull down menu select Toolbox

26 26 Build An EIDE Web Service 11. (Continued) Drag an OracleDataAdapter from the toolkit on to your design surface. This will bring up the Data Adapter Configuration Wizard. Click Next Click New Connection Enter the Oracle service name, username, and password for accessing your Oracle database. Click OK.

27 27 Build An EIDE Web Service 11. (Continued) You will be returned to the Data Adapter Configuration Wizard. Click Next to continue. When prompted for a Query type, take the default and click Next When prompted to Generate the SQL statements, click the Query Builder button. On the Add Table dialog, select eide_MessageInfo and click Add, then Close.

28 28 Build An EIDE Web Service 11. (Continued) On the Query Builder dialog, click * to select all columns, then click the OK button. On the Data Adapter Configuration Wizard dialog, click Finish.

29 29 Build An EIDE Web Service 11. (Continued) You have now created two ADO.NET constructs (and all of the C# code behind them): OracleDataAdapter1, and OracleConnection1. These objects understand the specifics of accessing your particular RDBMS software. Give the Data Adapter a reasonable name by right clicking on OracleDataAdapter1 and selecting Properties. Then change the Name Property to oracleDataAdapterMessageInfo

30 30 Build An EIDE Web Service 12.Setup the ADO.NET C# Dataset necessary to access your newly built table. Right Click on the EIDEService project in the Solution Explorer and select Add Add New Item. In the Add New Item dialog select the Dataset template and change the name to eide_MessageInfo.xsd. Click the Open button.

31 31 Build An EIDE Web Service 13.This will bring you to the Dataset Design editor. Build an Element that matches your table by Dragging the E symbol onto the designer. Fill it out as shown.

32 32 Build An EIDE Web Service 14.(Continued) You have now created all of the ADO.NET C# constructs necessary to access your database table. DataAdapter – Handles specifics of accessing data in your table DataSet -- A logical view of your table. DataConnection – Manages connecting to your database.

33 33 Build An EIDE Web Service 15. Put some meat in your web method Navigate your way back to your stubbed out web method (click on the EIDEService.asmx.cs tab and scroll down to the bottom.) Add the code below to initialize your dataset. (This is a logical in memory version of your table.) // // Instantiate MessageInfo dataset. // eide_MessageInfo datasetMessageInfo = new eide_MessageInfo(); oracleDataAdapterMessageInfo.Fill(datasetMessageInfo, "tblMessageInfo");

34 34 Build An EIDE Web Service 15. (Continued) Add code to insert the EIDE MessageInfo data into the dataset. // // Insert the MessageInfo into the dataset. // datasetMessageInfo.tblMessageInfo.AddtblMessageInfoRow( MessageInfo.SysGenID, MessageInfo.TimeStamp, MessageInfo.Sender, MessageInfo.Receiver, MessageInfo.EntityCode, MessageInfo.ProcessID, MessageInfo.DataSet, MessageInfo.ListID, MessageInfo.ResponseSysGenID, MessageInfo.Comment, 0, MessageInfo.UserID, 0 );

35 35 Build An EIDE Web Service 15. (Continued) add code to save the data. // Save the Data OracleDataAdapterMessageInfo.Update(dsMessageInfo, "tblMessageInfo");

36 36 Build An EIDE Web Service 15. (Continued) Finally, rather than returning null, add code to build the PutPIDReturn structure and return it. // Build and return appropriate response PutPIDResponse resp = new PutPIDResponse(); resp.ReplyBlock = new ReplyBlock(); resp.ReplyBlock.Reply = new ReplyType(); resp.ReplyBlock.Reply.ReplyCode = ReplyTypeReplyCode.processedOK; resp.ReplyBlock.Reply.ReplyText = "Message Info Successfully Saved." return resp;

37 37 Build An EIDE Web Service 16. OK! You are done. You have built a fully functional Web Service, capable of receiving XML over the internet, converting the XML to application data and saving it into a RDBMS. This is the only code you actually had to write. // Web Service method supporting EIDE PutPID function. [WebMethod] public PutPIDResponse PutPID( MessageInfoType MessageInfo, PIDType PID) { // Instantiate MessageInfo dataset. eide_MessageInfo datasetMessageInfo = new eide_MessageInfo(); OracleDataAdapterMessageInfo.Fill(datasetMessageInfo, "tblMessageInfo"); // Insert the MessageInfo into the dataset. datasetMessageInfo.tblMessageInfo.AddtblMessageInfoRow ( MessageInfo.SysGenID, MessageInfo.TimeStamp, MessageInfo.Sender, MessageInfo.Receiver, MessageInfo.EntityCode, MessageInfo.ProcessID, MessageInfo.DataSet, MessageInfo.ListID, MessageInfo.ResponseSysGenID, MessageInfo.Comment, 0, MessageInfo.UserID, 0 ); // Save the Data OracleDataAdapterMessageInfo.Update(datasetMessageInfo, "tblMessageInfo"); // Build and return appropriate response PutPIDResponse resp = new PutPIDResponse(); resp.ReplyBlock = new ReplyBlock(); resp.ReplyBlock.Reply = new ReplyType(); resp.ReplyBlock.Reply.ReplyCode = ReplyTypeReplyCode.processedOK; resp.ReplyBlock.Reply.ReplyText = "Message Info Successfully Saved." return resp; }

38 38 Build an EIDE Web Consumer 1.Start the Microsoft Development Environment.

39 39 Build an EIDE Web Consumer 2.Load a C# Console App template From the IDE, Select File New Blank Solution to bring up the New project dialog Select the project type, C# project Select the template, Console Application Change the name from ConsoleApplication1 to EIDEConsumer Click the OK button

40 40 Build an EIDE Web Consumer 3. Alter to use meaningful names. In the source code, change the Class name, to EIDEConsumer

41 41 4.Add the C# EIDE definitions to your new C# project by querying the EIDE Web Services WSDL. Right click on References in the solution explorer and select Add Web Reference In the Add Web Reference dialog, type in a location of ce/EIDEService.asmx Click the Add Reference button. Build an EIDE Web Consumer

42 42 Build an EIDE Web Consumer 5.Add using clauses at the top of your C# code. This allows us to avoid referencing the namespaces every time we access classes within. using EideConsumer.localhost; using System.Security.Cryptography.X509Certificates;

43 43 Build an EIDE Web Consumer 6. Build an EIDE MessageInfo structure with the following C# code in the body of your main() method // Instantiate an EIDE MessageInfo object MessageInfoType info = new MessageInfoType(); info.SysGenID = 1; info.TimeStamp = DateTime.Now; info.Sender = "Entity A"; info.Receiver = "Entity B"; info.EntityCode = "ENTA"; info.ProcessID = 2; info.DataSet = 3; info.ListID = 4; info.ProcessIDSpecified = true; info.ListIDSpecified = true; info.DataSetSpecified = true;

44 44 Build an EIDE Web Consumer 7. Build an EIDE PIDType structure with the following C# code in the body of your main() method // Instantiate an EIDE PID Object. PIDType pid = new PIDType(); pid.NumberofAccounts = 1; pid.InitialHourEnding = new DateTime(2004,3,22,5,0,0); pid.Accounts = new PIDTypeAccountsAccount[1]; pid.Accounts[0] = new PIDTypeAccountsAccount(); pid.Accounts[0].PidDescription = new PIDDescriptionType(); pid.Accounts[0].PidDescription.AccountCode = "AA"; pid.Accounts[0].PidDescription.StartTime = DateTime.Now; pid.Accounts[0].PidDescription.EndTime = DateTime.Now.AddHours(1);

45 45 Build an EIDE Web Consumer 8.Set up for the Web Service call by adding the following code: // Set up for the web service call. EIDEService service = new EIDEService();

46 46 Build an EIDE Web Consumer 9.Secure your Web Service Call using a X.509 compliant certificate with the following 2 lines of C# code: // Set up client certificate for communications with EIDE server. X509Certificate certificate = service.ClientCertificates.Add(certificate);

47 47 Build an EIDE Web Consumer 10. Add two more lines of C# code to make the Web Service call. // Call the EIDE PutPID Method PutPIDResponse ret; ret = service.PutPID(info, pid);

48 48 Build an EIDE Web Consumer 11.Finally, add some code that inspects the reply text generated by the Web Service. // Display the response Console.WriteLine(ret.ReplyBlock.Reply.ReplyText);

49 49 Build an EIDE Web Consumer 12. Now hit CTRL-F5 to compile and run your Web Consumer. If all went well, you should see the message Message Info Successfully Saved. returned from the Web Service call. You should also verify that the Web service stored the data that your web consumer sent to it.

50 50 Build an EIDE Web Consumer Done! You have successfully built a Web Service that offers the EIDE PutPID functionality, and a Web Consumer that utilizes it!

51 51 HTTP Request that was sent over the wire by your Web Consumer. POST /EIDEService/EIDEService.asmx HTTP/1.1 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol ) Content-Type: text/xml; charset=utf-8 SOAPAction: "http://EntityA.com/EIDE/PutPID" Content-Length: 1240 Expect: 100-continue Connection: Keep-Alive Host: localhost: T13:46: :00 Entity A Entity B ENTA T05:00: : T13:46: : T14:46: :00 AA

52 52 HTTP Response that was received from your Web Service. HTTP/ Continue Server: Microsoft-IIS/5.1 Date: Fri, 29 Oct :46:12 GMT X-Powered-By: ASP.NET HTTP/ OK Server: Microsoft-IIS/5.1 Date: Fri, 29 Oct :46:13 GMT X-Powered-By: ASP.NET X-AspNet-Version: Cache-Control: private, max-age=0 Content-Type: text/xml; charset=utf-8 Content-Length: 503 processedOK Message Info Successfully Saved.

53 53 Questions?, Need help? Send me an at


Download ppt "1 An Implementation of EIDE in C#.NET Mark T. Sundsten"

Similar presentations


Ads by Google