soap client

This commit is contained in:
naomiEve 2025-03-11 17:06:29 +01:00
parent b7789f0ce8
commit 223d347cb6
11 changed files with 396 additions and 15 deletions

View file

@ -1,15 +0,0 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");
for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}

View file

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/contentModel.xml
/projectSettingsUpdater.xml
/.idea.SoapClient.iml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View file

@ -0,0 +1,15 @@
{
"providerId": "Microsoft.Tools.ServiceModel.Svcutil",
"version": "2.1.0",
"ExtendedData": {
"inputs": [
"http://localhost:7779/ws/user?wsdl"
],
"namespaceMappings": [
"*, SoapClient.UserSOAPServiceImplService"
],
"outputFile": "UserSOAPServiceImplService.cs",
"targetFramework": "net8.0",
"typeReuseMode": "All"
}
}

View file

@ -0,0 +1,258 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace SoapClient.UserSOAPServiceImplService
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://soapsoapsoap.com/", ConfigurationName="SoapClient.UserSOAPServiceImplService.UserSOAPService")]
public interface UserSOAPService
{
[System.ServiceModel.OperationContractAttribute(Action="http://soapsoapsoap.com/UserSOAPService/addScoreRequest", ReplyAction="http://soapsoapsoap.com/UserSOAPService/addScoreResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
System.Threading.Tasks.Task<bool> addScoreAsync(int arg0, string arg1, double arg2);
[System.ServiceModel.OperationContractAttribute(Action="http://soapsoapsoap.com/UserSOAPService/getUsersListRequest", ReplyAction="http://soapsoapsoap.com/UserSOAPService/getUsersListResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.getUsersListResponse> getUsersListAsync(SoapClient.UserSOAPServiceImplService.getUsersListRequest request);
[System.ServiceModel.OperationContractAttribute(Action="http://soapsoapsoap.com/UserSOAPService/getUserByIdRequest", ReplyAction="http://soapsoapsoap.com/UserSOAPService/getUserByIdResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
System.Threading.Tasks.Task<string> getUserByIdAsync(int arg0);
[System.ServiceModel.OperationContractAttribute(Action="http://soapsoapsoap.com/UserSOAPService/calculateAverageScoreRequest", ReplyAction="http://soapsoapsoap.com/UserSOAPService/calculateAverageScoreResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, SupportFaults=true)]
[return: System.ServiceModel.MessageParameterAttribute(Name="return")]
System.Threading.Tasks.Task<double> calculateAverageScoreAsync(int arg0);
[System.ServiceModel.OperationContractAttribute(Action="http://soapsoapsoap.com/UserSOAPService/findActivitiesByScoreRequest", ReplyAction="http://soapsoapsoap.com/UserSOAPService/findActivitiesByScoreResponse")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.findActivitiesByScoreResponse> findActivitiesByScoreAsync(SoapClient.UserSOAPServiceImplService.findActivitiesByScoreRequest request);
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="getUsersList", WrapperNamespace="http://soapsoapsoap.com/", IsWrapped=true)]
public partial class getUsersListRequest
{
public getUsersListRequest()
{
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="getUsersListResponse", WrapperNamespace="http://soapsoapsoap.com/", IsWrapped=true)]
public partial class getUsersListResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
[System.Xml.Serialization.XmlArrayAttribute()]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] @return;
public getUsersListResponse()
{
}
public getUsersListResponse(string[] @return)
{
this.@return = @return;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="findActivitiesByScore", WrapperNamespace="http://soapsoapsoap.com/", IsWrapped=true)]
public partial class findActivitiesByScoreRequest
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
public string arg0;
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=1)]
public double arg1;
public findActivitiesByScoreRequest()
{
}
public findActivitiesByScoreRequest(string arg0, double arg1)
{
this.arg0 = arg0;
this.arg1 = arg1;
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
[System.ServiceModel.MessageContractAttribute(WrapperName="findActivitiesByScoreResponse", WrapperNamespace="http://soapsoapsoap.com/", IsWrapped=true)]
public partial class findActivitiesByScoreResponse
{
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="", Order=0)]
[System.Xml.Serialization.XmlArrayAttribute()]
[System.Xml.Serialization.XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string[] @return;
public findActivitiesByScoreResponse()
{
}
public findActivitiesByScoreResponse(string[] @return)
{
this.@return = @return;
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
public interface UserSOAPServiceChannel : SoapClient.UserSOAPServiceImplService.UserSOAPService, System.ServiceModel.IClientChannel
{
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Tools.ServiceModel.Svcutil", "2.1.0")]
public partial class UserSOAPServiceClient : System.ServiceModel.ClientBase<SoapClient.UserSOAPServiceImplService.UserSOAPService>, SoapClient.UserSOAPServiceImplService.UserSOAPService
{
/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);
public UserSOAPServiceClient() :
base(UserSOAPServiceClient.GetDefaultBinding(), UserSOAPServiceClient.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.UserSOAPServiceImplPort.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public UserSOAPServiceClient(EndpointConfiguration endpointConfiguration) :
base(UserSOAPServiceClient.GetBindingForEndpoint(endpointConfiguration), UserSOAPServiceClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public UserSOAPServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(UserSOAPServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public UserSOAPServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(UserSOAPServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}
public UserSOAPServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}
public System.Threading.Tasks.Task<bool> addScoreAsync(int arg0, string arg1, double arg2)
{
return base.Channel.addScoreAsync(arg0, arg1, arg2);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.getUsersListResponse> SoapClient.UserSOAPServiceImplService.UserSOAPService.getUsersListAsync(SoapClient.UserSOAPServiceImplService.getUsersListRequest request)
{
return base.Channel.getUsersListAsync(request);
}
public System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.getUsersListResponse> getUsersListAsync()
{
SoapClient.UserSOAPServiceImplService.getUsersListRequest inValue = new SoapClient.UserSOAPServiceImplService.getUsersListRequest();
return ((SoapClient.UserSOAPServiceImplService.UserSOAPService)(this)).getUsersListAsync(inValue);
}
public System.Threading.Tasks.Task<string> getUserByIdAsync(int arg0)
{
return base.Channel.getUserByIdAsync(arg0);
}
public System.Threading.Tasks.Task<double> calculateAverageScoreAsync(int arg0)
{
return base.Channel.calculateAverageScoreAsync(arg0);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.findActivitiesByScoreResponse> SoapClient.UserSOAPServiceImplService.UserSOAPService.findActivitiesByScoreAsync(SoapClient.UserSOAPServiceImplService.findActivitiesByScoreRequest request)
{
return base.Channel.findActivitiesByScoreAsync(request);
}
public System.Threading.Tasks.Task<SoapClient.UserSOAPServiceImplService.findActivitiesByScoreResponse> findActivitiesByScoreAsync(string arg0, double arg1)
{
SoapClient.UserSOAPServiceImplService.findActivitiesByScoreRequest inValue = new SoapClient.UserSOAPServiceImplService.findActivitiesByScoreRequest();
inValue.arg0 = arg0;
inValue.arg1 = arg1;
return ((SoapClient.UserSOAPServiceImplService.UserSOAPService)(this)).findActivitiesByScoreAsync(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.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}
private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.UserSOAPServiceImplPort))
{
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.UserSOAPServiceImplPort))
{
return new System.ServiceModel.EndpointAddress("http://localhost:7779/ws/user");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}
private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return UserSOAPServiceClient.GetBindingForEndpoint(EndpointConfiguration.UserSOAPServiceImplPort);
}
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return UserSOAPServiceClient.GetEndpointAddress(EndpointConfiguration.UserSOAPServiceImplPort);
}
public enum EndpointConfiguration
{
UserSOAPServiceImplPort,
}
}
}

53
SoapClient/Program.cs Normal file
View file

@ -0,0 +1,53 @@
using SoapClient.UserSOAPServiceImplService;
var client = new UserSOAPServiceClient(UserSOAPServiceClient.EndpointConfiguration.UserSOAPServiceImplPort);
try
{
const int userId = 1;
const string activity = ">";
const double score = 50.5;
var addScoreResult = await client.addScoreAsync(userId, activity, score);
Console.WriteLine($"addScoreAsync result: {addScoreResult}");
var usersListResponse = await client.getUsersListAsync();
Console.WriteLine("Users List:");
if (usersListResponse.@return != null)
{
foreach (var user in usersListResponse.@return)
{
Console.WriteLine($"- {user}");
}
}
else
{
Console.WriteLine("No users found.");
}
var userById = await client.getUserByIdAsync(userId);
Console.WriteLine($"User with ID {userId}: {userById}");
var averageScore = await client.calculateAverageScoreAsync(userId);
Console.WriteLine($"Average score for user {userId}: {averageScore}");
var activitiesResponse = await client.findActivitiesByScoreAsync(activity, score);
Console.WriteLine($"Activities matching '{activity}' with score {score}:");
if (activitiesResponse.@return != null)
{
foreach (var activityResult in activitiesResponse.@return)
{
Console.WriteLine($"- {activityResult}");
}
}
else
{
Console.WriteLine("No matching activities found.");
}
await client.CloseAsync();
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ServiceModel.Duplex" Version="4.10.*" />
<PackageReference Include="System.ServiceModel.Http" Version="4.10.*" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.10.*" />
<PackageReference Include="System.ServiceModel.Security" Version="4.10.*" />
<PackageReference Include="System.ServiceModel.Federation" Version="4.10.*" />
</ItemGroup>
</Project>

16
SoapClient/SoapClient.sln Normal file
View file

@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoapClient", "SoapClient.csproj", "{2475F92F-7933-4068-BE48-AF3AE6B8ACAA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2475F92F-7933-4068-BE48-AF3AE6B8ACAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2475F92F-7933-4068-BE48-AF3AE6B8ACAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2475F92F-7933-4068-BE48-AF3AE6B8ACAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2475F92F-7933-4068-BE48-AF3AE6B8ACAA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

7
SoapClient/global.json Normal file
View file

@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.0",
"rollForward": "latestMinor",
"allowPrerelease": false
}
}