Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Form1()
- {
- InitializeComponent();
- }
- private PostBoxServiceEndpoint PostBoxServiceEndpoint =
- new PostBoxServiceEndpoint(); //Webservis türetilir
- private LoginType Ltype = new LoginType(); //Login için gerekli tip
- DocumentType document = new DocumentType(); //Belgeyi çektiğimiz tip
- ResultType resultType = new ResultType(); //Bize dönecek sonuç tipi
- private void Form1_Load(object sender, EventArgs e)
- {
- System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("En");////Visual studio error dilini ingilizceye çeker, form load a yazılabilir
- Ltype.userName = "xxxxx";
- Ltype.passWord = "yyyyy";
- string uuid = "ETTN BURAYA GELECEK";
- string[] paramList = { "DOCUMENTTYPE=EINVOICE", "DATAFORMAT=UBL", "ISCANCEL=0" }; //belge bilgileri, türü v.b
- PostBoxServiceEndpoint.Login(Ltype, out bool LoginResult, out bool LoginResultSpecified,
- out string sessionID); //Login ol ve session id al
- MessageBox.Show(string.Format("LoginResult {0} \n LoginResultSpecified {1} \n SessionID {2}", LoginResult.ToString(), LoginResultSpecified.ToString(), sessionID));
- /////////////////////////////////////////// Belgeyi Dosya olarak almak
- resultType =PostBoxServiceEndpoint.GetDocumentData(sessionID, uuid, paramList,out document);//Dosyayı document olarak çek ve çekme durumunu getir
- MessageBox.Show(string.Format("resultCode{0} \n resultMsg {1} \n resultCodeSpecified {2} ", resultType.resultCode, resultType.resultMsg, resultType.resultCodeSpecified));
- //File.WriteAllBytes(@"c:\x\IlkDenemeFat.zip", document.binaryData.Value); //Dosyayı zip olarak yaz
- //////////////////////////////////////////
- var file = new MemoryStream(document.binaryData.Value); //Zip şeklinde gelen binarydata memorystream yapılıyor, verinin türü aslında byte[]
- using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) // Memorystream datamız ZipArchive oluyor ama read modunda
- {
- foreach (var entry in zip.Entries) //ZipArchive içerisindeki her dosya okunuyor
- {
- using (var streamXMLs = entry.Open()) //Dosyalar yine memoryde açılıyor
- {
- var xmlDocument = new XmlDocument(); //XmlDocument tanımlanıyor
- xmlDocument.Load(streamXMLs); //Dosya xmlDocumente yükleniyor
- var nsmgr = new XmlNamespaceManager(xmlDocument.NameTable); //Xml aslında ubl formatında ve bu formatta önekler geliyor bu yüzden de tanımlama yapmadan okumak mümkün değil
- //bu yüzden ön eki ve adını tanımlamamı lazım
- nsmgr.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"); //cbc ön eki ve önek adı tanımlanıyor
- var Ne1 = xmlDocument.SelectNodes("//cbc:PayableAmount[@currencyID='TRY']", nsmgr); // //önek:Node[@XmlAttiribute='attiributeDeğeri'] ve önek tanımlaması(namespace) parametre veriliyor
- MessageBox.Show(Ne1.Item(0).InnerText); //Sonunda değeri alıyoruz, aslında değerimiz bir tane ama döngüye koyarak aynı veriden olursa getirebiliriz
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement