Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Last active January 4, 2023 01:03
Show Gist options
  • Select an option

  • Save SelvinPL/9db05c6ad24614caf1011d57da64c987 to your computer and use it in GitHub Desktop.

Select an option

Save SelvinPL/9db05c6ad24614caf1011d57da64c987 to your computer and use it in GitHub Desktop.
paste działa.ps1 into powershell console https://dotnetfiddle.net/jm3Io6
$framework = "net6.0"
#installing svcutil for dotnet
dotnet tool install --global dotnet-svcutil
mkdir CRBRLib
Set-Location CRBRLib
#getting zip with wsdl
Invoke-WebRequest -Uri https://www.gov.pl/attachment/b9c58be1-560a-4c0c-b746-254336f49e41 -OutFile CRBR.zip
#unpack zip and execute svcutil tool
$wsdlFile = ($(Expand-Archive CRBR.zip -Verbose -Force *>&1 | Foreach-Object { if ($_.message -match "Created '(.*)'.*") { Get-Item $Matches[1] }}) | Select-Object -First 1).FullName
dotnet-svcutil $wsdlFile -tf $framework
#create new library project
dotnet new classlib --framework $framework
#adding required package
dotnet add package System.ServiceModel.Http
#delete unused files
Remove-Item Class1.cs
Remove-Item CRBR.zip
Set-Location ..
mkdir CRBR
Set-Location CRBR
#create $framework console project
dotnet new console --framework $framework
#adding reference to previously created library
dotnet add reference ../CRBRLib/CRBRLib.csproj
#setting content of Project.cs
Set-Content -Path Program.cs -Value 'using System.ServiceModel;
using System.ServiceModel.Channels;
var binding = new CustomBinding();
binding.Elements.Add(new TextMessageEncodingBindingElement());
binding.Elements.Add(new HttpsTransportBindingElement());
var client = new ApiPrzegladoweCRBRClient(binding, new EndpointAddress("https://bramka-crbr.mf.gov.pl:5058/uslugiBiznesowe/uslugiESB/AP/ApiPrzegladoweCRBR/2022/02/01"));
var req = new PobierzInformacjeOSpolkachIBeneficjentachTyp();
req.PobierzInformacjeOSpolkachIBeneficjentachDane = new PobierzInformacjeOSpolkachIBeneficjentachDaneTyp();
req.PobierzInformacjeOSpolkachIBeneficjentachDane.SzczegolyWniosku = new SzczegolyWnioskuTyp();
req.PobierzInformacjeOSpolkachIBeneficjentachDane.SzczegolyWniosku.ItemsElementName = new ItemsChoiceType[] { ItemsChoiceType.NIP };
req.PobierzInformacjeOSpolkachIBeneficjentachDane.SzczegolyWniosku.Items = new object[] { "1111111111" };
var resp = await client.PobierzInformacjeOSpolkachIBeneficjentachAsync(req);
System.Console.WriteLine(resp.PobierzInformacjeOSpolkachIBeneficjentachOdpowiedz.PobierzInformacjeOSpolkachIBeneficjentachOdpowiedzDane.Status);'
#compile and execute ... expected result "IstniejaInformacje" on standard output
dotnet run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment