Advertisement
Guest User

Untitled

a guest
Mar 14th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. public Form1()
  2. {
  3. InitializeComponent();
  4. }
  5.  
  6. private PostBoxServiceEndpoint PostBoxServiceEndpoint =
  7. new PostBoxServiceEndpoint(); //Webservis türetilir
  8.  
  9. private LoginType Ltype = new LoginType(); //Login için gerekli tip
  10. DocumentType document = new DocumentType(); //Belgeyi çektiğimiz tip
  11. ResultType resultType = new ResultType(); //Bize dönecek sonuç tipi
  12.  
  13. private void Form1_Load(object sender, EventArgs e)
  14. {
  15. System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("En");////Visual studio error dilini ingilizceye çeker, form load a yazılabilir
  16. Ltype.userName = "xxxxx";
  17. Ltype.passWord = "yyyyy";
  18. string uuid = "ETTN BURAYA GELECEK";
  19.  
  20. string[] paramList = { "DOCUMENTTYPE=EINVOICE", "DATAFORMAT=UBL", "ISCANCEL=0" }; //belge bilgileri, türü v.b
  21.  
  22. PostBoxServiceEndpoint.Login(Ltype, out bool LoginResult, out bool LoginResultSpecified,
  23. out string sessionID); //Login ol ve session id al
  24.  
  25. MessageBox.Show(string.Format("LoginResult {0} \n LoginResultSpecified {1} \n SessionID {2}", LoginResult.ToString(), LoginResultSpecified.ToString(), sessionID));
  26.  
  27. /////////////////////////////////////////// Belgeyi Dosya olarak almak
  28. resultType =PostBoxServiceEndpoint.GetDocumentData(sessionID, uuid, paramList,out document);//Dosyayı document olarak çek ve çekme durumunu getir
  29. MessageBox.Show(string.Format("resultCode{0} \n resultMsg {1} \n resultCodeSpecified {2} ", resultType.resultCode, resultType.resultMsg, resultType.resultCodeSpecified));
  30. //File.WriteAllBytes(@"c:\x\IlkDenemeFat.zip", document.binaryData.Value); //Dosyayı zip olarak yaz
  31. //////////////////////////////////////////
  32.  
  33. var file = new MemoryStream(document.binaryData.Value); //Zip şeklinde gelen binarydata memorystream yapılıyor, verinin türü aslında byte[]
  34. using (var zip = new ZipArchive(file, ZipArchiveMode.Read)) // Memorystream datamız ZipArchive oluyor ama read modunda
  35. {
  36. foreach (var entry in zip.Entries) //ZipArchive içerisindeki her dosya okunuyor
  37. {
  38. using (var streamXMLs = entry.Open()) //Dosyalar yine memoryde açılıyor
  39. {
  40. var xmlDocument = new XmlDocument(); //XmlDocument tanımlanıyor
  41. xmlDocument.Load(streamXMLs); //Dosya xmlDocumente yükleniyor
  42.  
  43. 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
  44. //bu yüzden ön eki ve adını tanımlamamı lazım
  45. nsmgr.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"); //cbc ön eki ve önek adı tanımlanıyor
  46.  
  47. var Ne1 = xmlDocument.SelectNodes("//cbc:PayableAmount[@currencyID='TRY']", nsmgr); // //önek:Node[@XmlAttiribute='attiributeDeğeri'] ve önek tanımlaması(namespace) parametre veriliyor
  48.  
  49. 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
  50.  
  51. }
  52. }
  53. }
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement