Exemple #1
0
        public void downloadDaneSzukaj(string nip)
        {
            if (nip != "")
            {
                if (!File.Exists(xmlPath + "\\DaneSzukaj\\" + nip + ".xml"))
                {
                    string        AdresUslugi = "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc";
                    WSHttpBinding myBinding   = new WSHttpBinding();
                    myBinding.Security.Mode = SecurityMode.Transport;
                    myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    myBinding.MessageEncoding = WSMessageEncoding.Mtom;
                    EndpointAddress         ea = new EndpointAddress(AdresUslugi);
                    UslugaBIRzewnPublClient cc = new UslugaBIRzewnPublClient(myBinding, ea);
                    cc.Open();
                    string strSID = cc.Zaloguj(bir1Key);
                    using (OperationContextScope scope = new OperationContextScope(cc.InnerChannel))
                    {
                        HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                        requestMessage.Headers.Add("sid", strSID);
                        OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                        //Szukaj
                        ParametryWyszukiwania objParametryGR1 = new ParametryWyszukiwania();
                        objParametryGR1.Nip = nip;
                        string searchXml = cc.DaneSzukaj(objParametryGR1);
                        File.WriteAllText(xmlPath + "\\DaneSzukaj\\" + nip + ".xml", searchXml);
                    }
                }
            }
        }
Exemple #2
0
        public static string regonFromNIP(string nip, string key)
        {
            try
            {
                string        AdresUslugi = "https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc";
                WSHttpBinding myBinding   = new WSHttpBinding();
                myBinding.Security.Mode = SecurityMode.Transport;
                myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                myBinding.MessageEncoding = WSMessageEncoding.Mtom;
                EndpointAddress         ea = new EndpointAddress(AdresUslugi);
                UslugaBIRzewnPublClient cc = new UslugaBIRzewnPublClient(myBinding, ea);
                cc.Open();
                string strSID = cc.Zaloguj(key);
                using (OperationContextScope scope = new OperationContextScope(cc.InnerChannel))
                {
                    HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty();
                    requestMessage.Headers.Add("sid", strSID);
                    OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage;

                    //Szukaj
                    ParametryWyszukiwania objParametryGR1 = new ParametryWyszukiwania();
                    objParametryGR1.Nip = nip;
                    string      searchXml = cc.DaneSzukaj(objParametryGR1);
                    XmlDocument xdoc      = new XmlDocument();
                    xdoc.LoadXml(searchXml);
                    string regon = xdoc.SelectSingleNode("root/dane/Regon").InnerText;
                    return(regon);
                }
            }
            catch
            {
                return("");
            }
        }
Exemple #3
0
        public GusCompanyInfo GetCompanyByNip(string nip)
        {
            nip = NormalizeNip(nip);

            UslugaBIRzewnPublClient client = null;

#if NETSTANDARD2_0
            //var a = new MessageEncodingBindingElement();
            var binding = new CustomBinding();
            binding.Elements.Add(new TextMessageEncodingBindingElement());
            binding.Elements.Add(new HttpsTransportBindingElement
            {
                AllowCookies           = true,
                MaxBufferSize          = int.MaxValue,
                MaxReceivedMessageSize = int.MaxValue
            });

            client = new UslugaBIRzewnPublClient(binding, new EndpointAddress(Address));
#else
            //client = new UslugaBIRzewnPublClient(
            //    new WSHttpBinding(SecurityMode.Transport) { MessageEncoding = WSMessageEncoding.Mtom },
            //    new EndpointAddress(Address));
            //client = new UslugaBIRzewnPublClient(
            //    new WSHttpBinding(SecurityMode.Transport) { MessageEncoding = WSMessageEncoding.Mtom },
            //    new EndpointAddress(Address));

            var binding = new CustomBinding();
            binding.Elements.Add(new MtomMessageEncodingBindingElement());
            binding.Elements.Add(new HttpsTransportBindingElement
            {
                AllowCookies           = true,
                MaxBufferSize          = int.MaxValue,
                MaxReceivedMessageSize = int.MaxValue
            });

            client = new UslugaBIRzewnPublClient(binding, new EndpointAddress(Address));
#endif
            using (var scope = new OperationContextScope(client.InnerChannel))
            {
                var sid = client.Zaloguj(_userKey);

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

                var result = client.DaneSzukaj(new ParametryWyszukiwania()
                {
                    Nip = nip
                });
                client.Wyloguj(sid);

                try
                {
                    var doc = new XmlDocument();
                    doc.LoadXml(result);
                    var json     = JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.None, true);
                    var response = JsonConvert.DeserializeObject <SearchDataResponse>(json);
                    if (response?.Data != null)
                    {
                        response.Data.Nip = nip;
                    }
                    return(response?.Data);
                }
                catch { }
            }
            return(null);
        }