GUS API i .NET Core

0

Witam.

Czy robił ktoś może integrację z BIR REGON korzystając z .NET Core lub .NET Standard? Próbuję to zrobić, tak, jak robiłem w .NET Framework czyli poprzez dodanie Connected Services i korzystanie z wygenerowanych metod. Problem polega na tym, że kodowanie przy komunikacji z ich API musi być w MTOM, czego teoretycznie .NET Core i .NET Framework nie obsługują. Poprzednio kodowania ustawiałem na obiekcie klasy WsHttpBinding, niestety teraz ta klasa nie jest dostępna, a w CustomHttpBinding tego kodowania też nie mogę ustawić. Czy pozostaje mi normalnie Postem wysyłać w stringach wysyłać XMLe ręcznie?

0

W Net standard MTOM działa poprawnie

            GusServices.UslugaBIRzewnPublClient bir = new GusServices.UslugaBIRzewnPublClient();
            bir.Endpoint.Address = new System.ServiceModel.EndpointAddress(@"https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc");

            System.ServiceModel.WSHttpBinding binding = (System.ServiceModel.WSHttpBinding)bir.Endpoint.Binding;
            binding.Security.Mode = System.ServiceModel.SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
            binding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Mtom;

            string sid = bir.Zaloguj(<Klucz>);
            OperationContextScope scope = new OperationContextScope(bir.InnerChannel);

            HttpRequestMessageProperty requestProperties = new HttpRequestMessageProperty();
            requestProperties.Headers.Add("sid", sid);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestProperties;

            GusServices.ParametryWyszukiwania nipData = new GusServices.ParametryWyszukiwania();
            nipData.Nip = <Nip do szukania>

                   string daneSzukajResponse = "";
                    try
                    {
                        daneSzukajResponse = bir.DaneSzukaj(nipData);
                    }
                    catch 
                    {
                        return
                    }

                    try {
                        DaneSzukaj.root daneSzukaj = null;
                        using (var reader = new StringReader(daneSzukajResponse))
                        {
                            XmlSerializer daneSzukajSerializer = new XmlSerializer(typeof(DaneSzukaj.root));
                            daneSzukaj = (DaneSzukaj.root)daneSzukajSerializer.Deserialize(reader);
                        }

                      }

wynik masz w daneSzukaj

0

Jeżeli chcesz to zrobić w Net Core to chyba najprościej zrobić to ręcznie.
Aktualnie jestem w trakcie pisania kodu obsługującego zapytanie do GUS w NetCore. Jeżeli byś chciał to pisz bezpośrednio.

0
Paweł Opiela napisał(a):

Jeżeli chcesz to zrobić w Net Core to chyba najprościej zrobić to ręcznie.
Aktualnie jestem w trakcie pisania kodu obsługującego zapytanie do GUS w NetCore. Jeżeli byś chciał to pisz bezpośrednio.

Czy udało Ci się pobrać dane z GUS w .Net Core?
Zamiast WSHttpBinding użyłem NetHttpBinding

NetHttpBinding binding = new NetHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.MessageEncoding = NetHttpMessageEncoding.Mtom;

Dostaję komunikat:
System.NotSupportedException: The value 'Mtom' is not supported in this context for the binding property 'MessageEncoding'.

0

Jak wyżej wspomniałem trzeba sobie ręcznie przygotować paczkę i nie ma żadnego problemu z pobraniem danych.

2

Wystarczy dodać paczkę https://www.nuget.org/packages/WcfCoreMtomEncoder

        var encoding = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement());
        var transport = new HttpsTransportBindingElement();

        var customBinding = new CustomBinding(encoding, transport);
        bir.Endpoint.Binding = customBinding;
0

Mam podobny problem podczas łączenia z API ZUS.
Korzystam właśnie z ww paczki https://www.nuget.org/packages/WcfCoreMtomEncoder i dostaję błąd "The size necessary to buffer the XML content exceeded the buffer quota."

Czy komuś udało się pobrać dane klientem napisanym w .NET Core lub .NET Standard?

0

Działa dla poniższych ustawień TransferMode.Streamed.

 var encoding = new MtomMessageEncoderBindingElement(new TextMessageEncodingBindingElement());
 encoding.MessageVersion = MessageVersion.Soap12WSAddressingAugust2004;
 var transport = new HttpsTransportBindingElement();
 transport.TransferMode = TransferMode.Streamed;
 var customBinding = new CustomBinding(encoding, transport);

1 użytkowników online, w tym zalogowanych: 0, gości: 1