1 / 93

Ekstern vegleiðing: At gera Webservice til Heldina

This guide explains how to develop a web service in .NET, including steps for creating a producer and consumer, configuring IIS, and secure connections. It covers setting up WSDL, integrating X-Road, and detailed instructions for both UI and command-line configuration.

jfarris
Download Presentation

Ekstern vegleiðing: At gera Webservice til Heldina

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Ekstern vegleiðing: At gera Webservice til Heldina Hendan vegleiðingin lýsir, hvussu ein webservice verður gjørd í .net, sum veitari av data (Producer)

  2. Fyritreytir og software sum skal installerast Uppseting av IIS WSDL til Heldina Producer við .net Consumer við .net Uppseting av samband millum WS

  3. 3 X-Road hands-on .NET training • Hands-on training: • Configure IIS • Describing X-Road Web Service • Creating and testing new X-Road Producer in .NET • Creating and testing new X-Road Consumer in .NET • Provider Secure connection • Consumer Secure connection • Example

  4. 4 Developmentenvironment • .NET framework (3.5/4.0/4.5) • IIS (7) • MS Visual studio (2010+) • Windows SDK • SoapUI (http://sourceforge.net/projects/soapui/files/)

  5. 5 Configure IIS • Using UI • On Windows • On Windows Server • Using CMD • Can be used on Windows/Windows Server

  6. 6 Configure IIS Using UI on Windows f • Open Windows Features dialog and select needed options.(type „turn windows features on or off“ on start search)

  7. 7 Configure IIS Using UI on Windows • Look for „Internet information Services“ • In „Security“ choose: • Client Certificate Mapping Authentication • IIS Client Certificate Mapping Authentication • In Common HTTP Features: • Directory Browsing • Static Content

  8. 8 Configure IIS Using UI on Windows Server • Open Server Manager • Select Roles -> Add Roles • Select „Web Server (IIS)“

  9. 9 Configure IIS Using UI on Windows Server • On Role Services check: • Common HTTP Features: • Static Content • Default Document • Directory Browsing • Application Development: • Asp.Net • .NET Extensibility • ASP • Security • Basic Auth • Client Certificate Mapping Auth • IIS Client Certificate Mapping Auth

  10. 10 Configure IIS Using CMD • To enable all needed features you need to run the next command: • start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-CGI;IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI

  11. 11 Describing X-Road Web Service • Start from scratch – sample.wsdl • Personalize service • Add custom operations • Define operations • Define messages • Define custom data types • Service endpoint

  12. 12 Describing X-Road Web Service Using Scratch • Begin from a X-Road blank sample.wsdl,file which contains only meta services for Security Server: • listMethods • Used by security server to show list of available operations. • testSystem • Used for checking Producer server status. • We are not allowed to change these two methods names, signature and etc.

  13. 13 Describing X-Road Web Service Personalize service • First step is to personalize your service.For this you need to change next occurrences to your own: • ProducerShortName -> The short name of your ministry • Only lowercase letters and “-” are allowed, no underscore! • SecurityServerAddress -> Security server proxy address • (not important for producer stage, only for customer) • PortName* -> You service port name (not important for consumers) • IServiceInterfaceName* -> The name of your service interface name • ProducerServiceName* -> Name of your Producer • PortTypeName* -> Name of operations set on producer

  14. 14 Describing X-Road Web Service Personalize service • For example: • ProducerShortName -> mot • SecurityServerAddress -> http://10.96.70.195/cgi-bin/consumer_proxy • PortName -> TeaPort • IServiceInterfaceName -> ITeaService • ProducerServiceName -> TeaService • PortTypeName -> TeaServices

  15. 15 Describing X-Road Web Service Add custom operations • Now create a list of available operations. • List operations in binding element: <bindingname="Binding "type="tns:PortType"> <soap:bindingstyle="document"transport="http://schemas.xmlsoap.org/soap/http"/> <operationname="op1"> ... </operation> <operationname="op2"> ... </operation> </binding>

  16. 16 Describing X-Road Web Service Add custom operations • Now we create a list of available operations. • Each custom operation must have next structure: • soap:operation • xrd:version • The input consists of 5 parts: • Consumer, producer, userId, id, service. • Output consists of 5 parts (same as input): • Consumer, producer, userId, id, service.

  17. 17 Describing X-Road Web Service Add custom operations • Example: <operationname="appList"> <soap:operationsoapAction="appList"style="document"/> <xrd:version>v1</xrd:version> <input> <soap:bodyparts="body"use="literal"/> <soap:headermessage="tns:standardheader"part="consumer"use="literal"/> <soap:headermessage="tns:standardheader"part="producer"use="literal"/> <soap:headermessage="tns:standardheader"part="userId"use="literal"/> <soap:headermessage="tns:standardheader"part="id"use="literal"/> <soap:headermessage="tns:standardheader"part="service"use="literal"/> </input> <output>...</output> </operation>

  18. 18 Describing X-Road Web Service Add custom operations • Each operation in binding has appropriate soapAction in portType operation list. <portTypename="PortType"> <operationname="op1"> ... </operation> <operationname="op2"> ... </operation> </portType>

  19. 19 Describing X-Road Web Service Add custom operations • Specify the input and output messages for each operation. <operationname="op1"> <documentation> <xrd:title>Short description.</xrd:title> </documentation> <inputmessage="tns:op1"/> <outputmessage="tns:op1Response"/> </operation>

  20. 20 Describing X-Road Web Service Add custom operations • Messages are listed inside the root („definitions“) element. <definitions ... namespaces...> <types> <schema>... types definition ...</schema> </types> <messagename="Msg name"> ... </message> ... other messages ... <portTypename="PortType">... port operations ...</portType> <bindingname="Binding "type="tns:PortType">... operations ...</binding> <servicename="ProducerService">...</service> </definitions>

  21. 21 Describing X-Road Web Service Add custom operations • Define message types for PortType operations. <messagename="op1msgReq"> <partname="body"element="tns:op1"/> </message> <messagename="op1msgRes"> <partname="body"element="tns:op1Response"/> </message>

  22. 22 Describing X-Road Web Service Add custom operations • Last step is to write the xsd schema of custom types we want to use. <definitions... namespaces ... > <types> <schemaxmlns="http://www.w3.org/2001/XMLSchema" xmlns:xrd="http://x-road.eu/xsd/x-road.xsd" targetNamespace="http://x-road.eu/xsd/x-road.xsd"> ... Definitions of data types to use in service ... </schema> </types> ... </definitions>

  23. 23 Describing X-Road Web Service Service endpoint • Element <service> describe the producer endpoint configuration. <definitions> ... <servicename="TestSoapService"> <wsdl:portname="Test"binding="tns:TestSoapBinding"> <soap:addresslocation="http://localhost:6421/training/Test"/> <xrd:title>Test Service Endpoint</xrd:title> <xrd:addressproducer="aktorstest3"/> </wsdl:port> </service> </definitions>

  24. 24 Describing X-Road Web Service Service endpoint • Names of service and port is not important to Security Server. It is Up to you to give meaningful names. • Important is address location and producer name: • Soap location address is security server proxy address ([sec server IP]/cgi-bin/consumer_proxy) Not important for Producer itself. It describes a service endpoint for client. Each client has its own Security Server to send requests. • Producername is an organization short name.

  25. 25 Describing X-Road Web Service Service endpoint • After refactoring: • An example of service endpoint configuration. It can be skipped for producers, because consumer configure its own endpoint. <servicename="PeopleRegister"> <wsdl:portname="PeopleRegisterPort"binding="tns:PeopleRegisterBinding"> <soap:addresslocation="http://172.25.200.131/cgi-bin/consumer_proxy/"/> <xrd:title>People Register services</xrd:title> <xrd:addressproducer="aktorstest2"/> </wsdl:port> </service> </definitions>

  26. 26 Create Producer using ASP.NET • Prepare working files. • Sample Project • Code Generation • Implementing Service • Test service • Deploy on IIS Server

  27. 27 Create Producer using ASP.NET Working files • We will create a Web Service interface via Web Services Description Language Tool(wsdl.exe) • Training samples files folder: c:\training\NET_example • Sample WSDL: • training_eu.wsdl • Sample C# files: • Blank.wsdl ,training_eu.wsdl,GenerateCode.bat

  28. 28 Create Producer using ASP.NET Working files • Change the name of sample WSDL file • training_eu.wsdl->mot.wsdl as an example • In service provider namespace: • Find all instances of sample provider name in file and replace „aktorstest3“ with your real service provider short name: • http://aktorstest3.x-road.eu/producer • I will use “mot” instead of aktorstest3as an example

  29. 29 Create Producer using ASP.NET Sample Project • Create a new project • Select:  • File -> New -> Project -> ASP.NET Web Service Application

  30. 30 Create Producer using ASP.NET Sample Project • Enter a Project name: Producer • Include to project training files • Producer-> Add ->New Folder -> wsdl • Producer-> Add ->Existing Item -> (Browse for mot.wsdl file in training folder)

  31. 31 Create Producer using ASP.NET Sample Project • In file properties change next options: • Mark imported file as a “Content” to prevent changes directory of file. • Always copy to output directory

  32. 32 Create Producer using ASP.NET Code Generation • Generate CSharp code: • In training folder run GenerateCode.bat • ! NB before running script make sure that the full name of inputwsdl file and output file are correct.

  33. 33 Create Producer using ASP.NET Code Generation • Attach generated code to solution: • Producer-> Add ->Existing Item -> (Browse for ITeaService.cs file in trainig folder) • For better reading you can refactor some class names: • @string -> ConsumerHeader • string1 -> ProducerHeader • string2 -> UserIdHeader • string3 -> IdHeader • string4 -> ServiceHeader

  34. 34 Create Producer using ASP.NET Code Generation • For changed classes remove all occurrences of the attribute in header class types: • Or • The reason why we do it is the file generation tool use attribute types as class names, but we can not have duplicate class names. [System.Xml.Serialization.XmlTypeAttribute(TypeName="string", Namespace="http://www.w3.org/2001/XMLSchema")] [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.w3.org/2001/XMLSchema")]

  35. 35 Create Producer using ASP.NET Implementing Service • Delete default Service1.asmx and create XRoadService.asmx • Make it an implementation of the generated service public class XRoadService : ITeaService • Add attributes to XRoadService class: • Replace in namespace shortname „aktorstest3“ with your real service provider short name [WebService(Namespace = "http://mot.x-road.ee/producer")] [SoapDocumentService(RoutingStyle =SoapServiceRoutingStyle.RequestElement)]

  36. 36 Create Producer using ASP.NET Implementing Service • Implement all members: • Headers : • consumer,producer,userId,Id,service as properties. • Methods: • Custom methods: • listDist • etc. … • System methods: • listMethods – used by Security Server to obtain a list of custom operations • testSystem – used By Security Server to check producer status.

  37. 37 Create Producer using ASP.NET Implementing Service • listMethods(object request): • Parse WSDL file and show operation list from binding element. • Filter system methods that is used by Security Server • (Check the notes section for code sample) • testSystem(object request): • Good place to run tests or check database connection.

  38. 38 Create Producer using ASP.NET Implementing Service • Custom Method listDist(listDistReq listDistReq) example

  39. 39 Create Producer using ASP.NET Implementing Service • Service must copy all request SOAP message header fields into the response SOAP message header. • IXroadServicepersonList method • …. • [SoapHeaderAttribute("consumer", Direction = SoapHeaderDirection.InOut)] • [SoapHeaderAttribute("id", Direction = SoapHeaderDirection.InOut)] • [SoapHeaderAttribute("service", Direction = SoapHeaderDirection.InOut)] • [SoapHeaderAttribute("producer", Direction = SoapHeaderDirection.InOut)] • [SoapHeaderAttribute("userId", Direction = SoapHeaderDirection.InOut)] • ....

  40. 40 Create Producer using ASP.NET Implementing Service • Service must copy all request parameters to response message also. • Change file XRoadService.asmx, data service method: personList • …. • // X-road: <request> element in response message must contain the same elements as were in the request message return new listDistRes { request = new listDistResRequest { namePart = listDistReq.request.namePart }, ... };

  41. 41 Create Producer using ASP.NET Implementing Service • The new service is now created: • Push Run to see the result • The service now runs on VS built in IIS, open web browser at: http://localhost:54879/TeaService.asmx

  42. 42 Service testing in training environment Training computer: X-Road service provider; test client Security server: service providers SOAP request (2.3) IIS server Service provider SOAP response (2.4) request (1.1) response (1.2) request (2.2) response (2.5) Security server: service consumers SOAP client SOAP request (2.1) consumer SOAP response (2.6) WEB browser X-Road MISP2 server X-Road central server

  43. 43 Create Producer using ASP.NET Deploy on IIS Server • In Solution Explorer, select • MyXroadService-> Publish • On profile tab, select “new” and type “XRoadProfile” Next ->

  44. 44 Create Producer using ASP.NET Deploy on IIS Server • On Connection choose “Publish method -> File system” • Set destination as C:\inetpub\wwwroot\Service or your own Next ->

  45. 45 Create Producer using ASP.NET Deploy on IIS Server • On Setting, choose the right configuration. • “Delete all existing files to publish” is optional Next ->

  46. 46 Create Producer using ASP.NET Deploy on IIS Server • On Preview step. • After publishing step the new folder with the project will appear in the IIS root catalog. • The next step is Configure IIS Publish

  47. 47 Create Producer using ASP.NET Deploy on IIS Server • Create a new web site: • Sites-> Add Web Site • Set destination as C:\inetpub\wwwroot\Service or your own

  48. 48 Create Producer using ASP.NET Deploy on IIS Server • New web site properties: • Name: XroadService • Path: (Service Deployment path) • IP: (Select one of available) • Port: Available port (for example 92) • Press “OK”

  49. 49 Create Producer using ASP.NET Deploy on IIS Server • Our service must be available from IIS

  50. 50 Create Consumer • Initial data • Create project • Service reference • Configure client • Test client • Best practice

More Related