From d3e98b0dbe57bd931cd1d14b4b225f3df0a871b1 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Thu, 6 Jun 2024 14:09:50 +0200 Subject: [PATCH] Create a client for the ranking service --- .../ConnectedService.json | 45 ++++ .../RankingServiceReference/Reference.cs | 222 ++++++++++++++++++ Tasks/Lab7/RankingClient/Program.cs | 8 + Tasks/Lab7/RankingClient/RankingClient.csproj | 18 ++ Tasks/Lab7/RankingClient/RankingClient.sln | 25 ++ 5 files changed, 318 insertions(+) create mode 100644 Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/ConnectedService.json create mode 100644 Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/Reference.cs create mode 100644 Tasks/Lab7/RankingClient/Program.cs create mode 100644 Tasks/Lab7/RankingClient/RankingClient.csproj create mode 100644 Tasks/Lab7/RankingClient/RankingClient.sln diff --git a/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/ConnectedService.json b/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/ConnectedService.json new file mode 100644 index 0000000..45a52e5 --- /dev/null +++ b/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/ConnectedService.json @@ -0,0 +1,45 @@ +{ + "ExtendedData": { + "inputs": [ + "http://localhost:8081/ranking/RankingService?wsdl" + ], + "collectionTypes": [ + "System.Array", + "System.Collections.Generic.Dictionary`2" + ], + "namespaceMappings": [ + "*, RankingServiceReference" + ], + "references": [ + "Microsoft.Extensions.ObjectPool, {Microsoft.Extensions.ObjectPool, 6.0.16}", + "Microsoft.IdentityModel.Logging, {Microsoft.IdentityModel.Logging, 6.8.0}", + "Microsoft.IdentityModel.Protocols.WsTrust, {Microsoft.IdentityModel.Protocols.WsTrust, 6.8.0}", + "Microsoft.IdentityModel.Tokens, {Microsoft.IdentityModel.Tokens, 6.8.0}", + "Microsoft.IdentityModel.Tokens.Saml, {Microsoft.IdentityModel.Tokens.Saml, 6.8.0}", + "Microsoft.IdentityModel.Xml, {Microsoft.IdentityModel.Xml, 6.8.0}", + "System.Formats.Asn1, {System.Formats.Asn1, 6.0.0}", + "System.IO, {System.IO, 4.3.0}", + "System.Reflection.DispatchProxy, {System.Reflection.DispatchProxy, 4.7.1}", + "System.Runtime, {System.Runtime, 4.3.0}", + "System.Security.AccessControl, {System.Security.AccessControl, 6.0.0}", + "System.Security.Cryptography.Cng, {System.Security.Cryptography.Cng, 4.5.0}", + "System.Security.Cryptography.Pkcs, {System.Security.Cryptography.Pkcs, 6.0.1}", + "System.Security.Cryptography.Xml, {System.Security.Cryptography.Xml, 6.0.1}", + "System.Security.Principal.Windows, {System.Security.Principal.Windows, 5.0.0}", + "System.ServiceModel.Duplex, {System.ServiceModel.Duplex, 6.0.0}", + "System.ServiceModel.Federation, {System.ServiceModel.Federation, 6.0.0}", + "System.ServiceModel.Http, {System.ServiceModel.Http, 6.0.0}", + "System.ServiceModel.NetFramingBase, {System.ServiceModel.NetFramingBase, 6.0.0}", + "System.ServiceModel.NetTcp, {System.ServiceModel.NetTcp, 6.0.0}", + "System.ServiceModel.Primitives, {System.ServiceModel.Primitives, 6.0.0}", + "System.ServiceModel.Security, {System.ServiceModel.Security, 6.0.0}", + "System.Text.Encoding, {System.Text.Encoding, 4.3.0}", + "System.Threading.Tasks, {System.Threading.Tasks, 4.3.0}", + "System.Xml.ReaderWriter, {System.Xml.ReaderWriter, 4.3.0}", + "System.Xml.XmlDocument, {System.Xml.XmlDocument, 4.3.0}" + ], + "sync": true, + "targetFramework": "net8.0", + "typeReuseMode": "All" + } +} \ No newline at end of file diff --git a/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/Reference.cs b/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/Reference.cs new file mode 100644 index 0000000..3e15e0d --- /dev/null +++ b/Tasks/Lab7/RankingClient/Connected Services/RankingServiceReference/Reference.cs @@ -0,0 +1,222 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace RankingServiceReference +{ + + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + [System.ServiceModel.ServiceContractAttribute(Namespace="http://ranking/", ConfigurationName="RankingServiceReference.RankingService")] + public interface RankingService + { + + // CODEGEN: Parameter 'return' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'Microsoft.Xml.Serialization.XmlArrayAttribute'. + [System.ServiceModel.OperationContractAttribute(Action="http://ranking/RankingService/rankingListRequest", ReplyAction="http://ranking/RankingService/rankingListResponse")] + [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)] + [return: System.ServiceModel.MessageParameterAttribute(Name="return")] + RankingServiceReference.rankingListResponse rankingList(RankingServiceReference.rankingListRequest request); + + [System.ServiceModel.OperationContractAttribute(Action="http://ranking/RankingService/rankingListRequest", ReplyAction="http://ranking/RankingService/rankingListResponse")] + System.Threading.Tasks.Task rankingListAsync(RankingServiceReference.rankingListRequest request); + } + + /// + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://ranking/")] + public partial class competitor + { + + private string nameField; + + private string timeField; + + /// + [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=0)] + public string name + { + get + { + return this.nameField; + } + set + { + this.nameField = value; + } + } + + /// + [System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=1)] + public string time + { + get + { + return this.timeField; + } + set + { + this.timeField = value; + } + } + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + [System.ServiceModel.MessageContractAttribute(WrapperName="rankingList", WrapperNamespace="http://ranking/", IsWrapped=true)] + public partial class rankingListRequest + { + + public rankingListRequest() + { + } + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + [System.ServiceModel.MessageContractAttribute(WrapperName="rankingListResponse", WrapperNamespace="http://ranking/", IsWrapped=true)] + public partial class rankingListResponse + { + + [System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)] + [System.Xml.Serialization.XmlArrayAttribute()] + [System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)] + public RankingServiceReference.competitor[] @return; + + public rankingListResponse() + { + } + + public rankingListResponse(RankingServiceReference.competitor[] @return) + { + this.@return = @return; + } + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + public interface RankingServiceChannel : RankingServiceReference.RankingService, System.ServiceModel.IClientChannel + { + } + + [System.Diagnostics.DebuggerStepThroughAttribute()] + [System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.2.0-preview1.23462.5")] + public partial class RankingServiceClient : System.ServiceModel.ClientBase, RankingServiceReference.RankingService + { + + /// + /// Implement this partial method to configure the service endpoint. + /// + /// The endpoint to configure + /// The client credentials + static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials); + + public RankingServiceClient() : + base(RankingServiceClient.GetDefaultBinding(), RankingServiceClient.GetDefaultEndpointAddress()) + { + this.Endpoint.Name = EndpointConfiguration.RankingServicePort.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public RankingServiceClient(EndpointConfiguration endpointConfiguration) : + base(RankingServiceClient.GetBindingForEndpoint(endpointConfiguration), RankingServiceClient.GetEndpointAddress(endpointConfiguration)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public RankingServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) : + base(RankingServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress)) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public RankingServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : + base(RankingServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) + { + this.Endpoint.Name = endpointConfiguration.ToString(); + ConfigureEndpoint(this.Endpoint, this.ClientCredentials); + } + + public RankingServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) : + base(binding, remoteAddress) + { + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + RankingServiceReference.rankingListResponse RankingServiceReference.RankingService.rankingList(RankingServiceReference.rankingListRequest request) + { + return base.Channel.rankingList(request); + } + + public RankingServiceReference.competitor[] rankingList() + { + RankingServiceReference.rankingListRequest inValue = new RankingServiceReference.rankingListRequest(); + RankingServiceReference.rankingListResponse retVal = ((RankingServiceReference.RankingService)(this)).rankingList(inValue); + return retVal.@return; + } + + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)] + System.Threading.Tasks.Task RankingServiceReference.RankingService.rankingListAsync(RankingServiceReference.rankingListRequest request) + { + return base.Channel.rankingListAsync(request); + } + + public System.Threading.Tasks.Task rankingListAsync() + { + RankingServiceReference.rankingListRequest inValue = new RankingServiceReference.rankingListRequest(); + return ((RankingServiceReference.RankingService)(this)).rankingListAsync(inValue); + } + + public virtual System.Threading.Tasks.Task OpenAsync() + { + return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action(((System.ServiceModel.ICommunicationObject)(this)).EndOpen)); + } + + private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.RankingServicePort)) + { + System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding(); + result.MaxBufferSize = int.MaxValue; + result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max; + result.MaxReceivedMessageSize = int.MaxValue; + result.AllowCookies = true; + return result; + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration) + { + if ((endpointConfiguration == EndpointConfiguration.RankingServicePort)) + { + return new System.ServiceModel.EndpointAddress("http://localhost:8081/ranking/RankingService"); + } + throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration)); + } + + private static System.ServiceModel.Channels.Binding GetDefaultBinding() + { + return RankingServiceClient.GetBindingForEndpoint(EndpointConfiguration.RankingServicePort); + } + + private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() + { + return RankingServiceClient.GetEndpointAddress(EndpointConfiguration.RankingServicePort); + } + + public enum EndpointConfiguration + { + + RankingServicePort, + } + } +} diff --git a/Tasks/Lab7/RankingClient/Program.cs b/Tasks/Lab7/RankingClient/Program.cs new file mode 100644 index 0000000..70035a4 --- /dev/null +++ b/Tasks/Lab7/RankingClient/Program.cs @@ -0,0 +1,8 @@ +// See https://aka.ms/new-console-template for more information +RankingServiceReference.RankingServiceClient client = new RankingServiceReference.RankingServiceClient(RankingServiceReference.RankingServiceClient.EndpointConfiguration.RankingServicePort); +RankingServiceReference.competitor[] competitors = client.rankingList(); + +for (int i = 0; i < competitors.Length; i++) +{ + Console.WriteLine($"{i + 1}. {competitors[i].name}, {competitors[i].time}"); +} diff --git a/Tasks/Lab7/RankingClient/RankingClient.csproj b/Tasks/Lab7/RankingClient/RankingClient.csproj new file mode 100644 index 0000000..4a48f1a --- /dev/null +++ b/Tasks/Lab7/RankingClient/RankingClient.csproj @@ -0,0 +1,18 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + + + + diff --git a/Tasks/Lab7/RankingClient/RankingClient.sln b/Tasks/Lab7/RankingClient/RankingClient.sln new file mode 100644 index 0000000..0926393 --- /dev/null +++ b/Tasks/Lab7/RankingClient/RankingClient.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.10.34928.147 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RankingClient", "RankingClient.csproj", "{1F5101DA-36BF-4B94-811A-10BC0D85DB3D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1F5101DA-36BF-4B94-811A-10BC0D85DB3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F5101DA-36BF-4B94-811A-10BC0D85DB3D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F5101DA-36BF-4B94-811A-10BC0D85DB3D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F5101DA-36BF-4B94-811A-10BC0D85DB3D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A04AF648-3A85-4288-B4CC-24BC3416ABE6} + EndGlobalSection +EndGlobal