public string Connect(string nips)
        {
            WSHttpBinding myBinding = new WSHttpBinding();

            myBinding.Security.Mode = SecurityMode.Transport;
            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            myBinding.MessageEncoding = WSMessageEncoding.Mtom;


            EndpointAddress         ea      = new EndpointAddress("https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc");
            UslugaBIRzewnPublClient service = new UslugaBIRzewnPublClient(myBinding, ea);

            service.Open();

            string sid = service.Zaloguj("abcde12345abcde12345");

            new OperationContextScope(service.InnerChannel);

            HttpRequestMessageProperty reqProps = new HttpRequestMessageProperty();

            reqProps.Headers.Add("sid", sid);

            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = reqProps;
            ParametryWyszukiwania parametryWyszukiwania = new ParametryWyszukiwania();

            parametryWyszukiwania.Nipy = nips;

            return(service.DaneSzukajPodmioty(parametryWyszukiwania));
        }
Exemplo n.º 2
0
        public void downloadPublDaneRaportFizycznaOsoba(string regon)
        {
            if (regon != "")
            {
                if (!File.Exists(xmlPath + "\\PublDaneRaportFizycznaOsoba\\" + regon + ".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();
                        string xmlFullRaport = cc.DanePobierzPelnyRaport(regon, "PublDaneRaportFizycznaOsoba");
                        File.WriteAllText(xmlPath + "\\PublDaneRaportFizycznaOsoba\\" + regon + ".xml", xmlFullRaport);
                    }
                }
            }
        }
Exemplo n.º 3
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("");
            }
        }
Exemplo n.º 4
0
        private static void Login()
        {
            sid = client.Zaloguj(USER_KEY);
            OperationContextScope      scope    = new OperationContextScope(client.InnerChannel);
            HttpRequestMessageProperty reqProps = new HttpRequestMessageProperty();

            reqProps.Headers.Add("sid", sid);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = reqProps;
        }
Exemplo n.º 5
0
        private static string Login()
        {
            if (Client != null && !string.IsNullOrEmpty(Sid))
            {
                Client.Wyloguj(Sid);
                Client.Close();
            }
            var appSettings = ConfigurationManager.AppSettings;
            var apiKey      = appSettings["GusProdKey"];

            Client = new UslugaBIRzewnPublClient();
            Client.Open();
            Sid = Client.Zaloguj(apiKey);
            if (string.IsNullOrEmpty(Sid))
            {
                apiKey = appSettings["GusTestKey"];
                Sid    = Client.Zaloguj(apiKey);
            }
            return(Sid);
        }
Exemplo n.º 6
0
        private void LogIn(bool isFirstTime)
        {
            try
            {
                _sid = _client.Zaloguj(_sidLogin);
            }
            catch (Exception e)
            {
                throw new BiRClientSetUpException("Błąd podczas logowania do usługi BiR", e);
            }

            if (string.IsNullOrEmpty(_sid) && !isFirstTime)
            {
                throw new CommunicationException("SID po zalogowowaniu jest Login pusty");
            }
        }
Exemplo n.º 7
0
        public void PolaczBIRpub()
        {
            //Create the binding.
            var myBinding = new WSHttpBinding(SecurityMode.Transport);

            myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
            myBinding.MessageEncoding = WSMessageEncoding.Mtom;

            var ea     = new EndpointAddress("https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc"); //test
            var client = new UslugaBIRzewnPublClient(myBinding, ea);

            client.Open();

            //logowanie bez sida
            string sid = client.Zaloguj("123456789");

            using (new OperationContextScope(client.InnerChannel))
            {
                var requestMessage = new System.ServiceModel.Channels.HttpRequestMessageProperty();
                requestMessage.Headers["sid"] = sid;
                OperationContext.Current.OutgoingMessageProperties[System.ServiceModel.Channels.HttpRequestMessageProperty.Name] = requestMessage;

                var paramGR1 = new UslugaBIRzewnPublClient();
            }
//'DANE SZUKAJ 1
//Dim objParametryGR1 As New UslugaBIRpubl.ParametryWyszukiwania
//objParametryGR1.Nip = "1111111111"
//txtResult.Text &= "### DaneSzukaj (grupa 1):" & vbCrLf &
//cc.DaneSzukaj(objParametryGR1) & vbCrLf & vbCrLf
//''DANE POBIERZ PEŁNY RAPORT
//txtResult.Text &= "### DanePobierzPelnyRaport:" & vbCrLf &
//cc.DanePobierzPelnyRaport("39002176400000", "PublDaneRaportPrawna", "") & vbCrLf &
//vbCrLf
//'WYLOGUJ
//txtResult.Text &= "### Wyloguj:" & vbCrLf & cc.Wyloguj(strSID) & vbCrLf &
//vbCrLf
//'GET VALUE
//txtResult.Text &= "### GetValue(KomunikatKod):" & vbCrLf &
//cc.GetValue("KomunikatKod") & vbCrLf
//txtResult.Text &= "### GetValue(KomunikatTresc):" & vbCrLf &
//cc.GetValue("KomunikatTresc") & vbCrLf
//txtResult.Text &= "### GetValue(StatusSesji):" & vbCrLf &
//cc.GetValue("StatusSesji") & vbCrLf
//End Using
//cc.Close()
//End Sub
        }
Exemplo n.º 8
0
        public static UslugaBIRzewnPublClient ConBIR() //Metoda Logująca się do GUSu i ustawiająca sid jako header komunikatów
        {
            GusKey                  apiKey    = new GusKey();
            WSHttpBinding           myBinding = Binding();
            EndpointAddress         ea        = new EndpointAddress("https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc");
            UslugaBIRzewnPublClient cc        = new UslugaBIRzewnPublClient(myBinding, ea);

            cc.Open();
            string sid = cc.Zaloguj(apiKey.Key);

            Console.WriteLine("Zaloguj " + sid);
            OperationContextScope      scope    = new OperationContextScope(cc.InnerChannel);
            HttpRequestMessageProperty reqProps = new HttpRequestMessageProperty();

            reqProps.Headers.Add("sid", sid);
            OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = reqProps;
            return(cc);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        private void buttonSearch_Click(object sender, EventArgs e)
        {
            labelErrorMsg.Visible = false;

            UslugaBIRzewnPublClient polaczenie = new UslugaBIRzewnPublClient();
            string sid = polaczenie.Zaloguj("abcde12345abcde12345");

            try
            {
                //Środowisko testowe usługi BIR1.1
                OperationContextScope scope = new OperationContextScope(polaczenie.InnerChannel);

                HttpRequestMessageProperty requestMessageProperty = new HttpRequestMessageProperty();
                requestMessageProperty.Headers.Add("sid", sid);

                OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessageProperty;

                StringBuilder sb = new StringBuilder();
                foreach (object o in listBoxNIP.SelectedItems)
                {
                    sb.AppendLine(o.ToString());
                }
                string s = sb.ToString();

                ParametryWyszukiwania parametryWyszukiwania = new ParametryWyszukiwania();
                parametryWyszukiwania.Nipy = s;

                DataSet      dataSet = new DataSet();
                StringReader sr      = new StringReader(polaczenie.DaneSzukajPodmioty(parametryWyszukiwania));

                string przekazanieKomunikatu = polaczenie.GetValue("KomunikatKod");
                int    zwracanaWartosc       = Convert.ToInt32(przekazanieKomunikatu);

                dataSet.ReadXml(sr);

                PrepareDataGridView1ForData();

                if (zwracanaWartosc == 4)
                {
                    labelErrorMsg.Visible = true;
                    labelErrorMsg.Text    = "Nie znaleziono żadnych podmiotów gospodarczych.";
                }

                else
                {
                    dataGridView1.AutoGenerateColumns = false;
                    dataGridView1.ColumnCount         = 6;

                    dataGridView1.Columns[0].Name             = "Regon";
                    dataGridView1.Columns[0].HeaderText       = "REGON";
                    dataGridView1.Columns[0].DataPropertyName = "Regon";

                    dataGridView1.Columns[1].HeaderText       = "Nip";
                    dataGridView1.Columns[1].Name             = "NIP";
                    dataGridView1.Columns[1].DataPropertyName = "Nip";

                    dataGridView1.Columns[2].Name             = "Nazwa";
                    dataGridView1.Columns[2].HeaderText       = "Nazwa";
                    dataGridView1.Columns[2].DataPropertyName = "Nazwa";

                    dataGridView1.Columns[3].Name             = "Ulica";
                    dataGridView1.Columns[3].HeaderText       = "Ulica";
                    dataGridView1.Columns[3].DataPropertyName = "Ulica";

                    dataGridView1.Columns[4].Name             = "Miejscowosc";
                    dataGridView1.Columns[4].HeaderText       = "Miejscowość";
                    dataGridView1.Columns[4].DataPropertyName = "Miejscowosc";

                    dataGridView1.Columns[5].Name             = "KodPocztowy";
                    dataGridView1.Columns[5].HeaderText       = "Kod Pocztowy";
                    dataGridView1.Columns[5].DataPropertyName = "KodPocztowy";

                    dataGridView1.DataSource = dataSet.Tables[0];
                }
            }
            catch (Exception)
            {
                string error   = "Usługa BIR1 niedostępna lub żaden identyfikator NIP nie został dodany do listy wyszukiwania.";
                string caption = "Błąd";
                MessageBox.Show(error, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            polaczenie.Wyloguj(sid);
        }