<tfoot id='n3xf1'></tfoot>
    • <bdo id='n3xf1'></bdo><ul id='n3xf1'></ul>

  • <i id='n3xf1'><tr id='n3xf1'><dt id='n3xf1'><q id='n3xf1'><span id='n3xf1'><b id='n3xf1'><form id='n3xf1'><ins id='n3xf1'></ins><ul id='n3xf1'></ul><sub id='n3xf1'></sub></form><legend id='n3xf1'></legend><bdo id='n3xf1'><pre id='n3xf1'><center id='n3xf1'></center></pre></bdo></b><th id='n3xf1'></th></span></q></dt></tr></i><div id='n3xf1'><tfoot id='n3xf1'></tfoot><dl id='n3xf1'><fieldset id='n3xf1'></fieldset></dl></div>

    1. <small id='n3xf1'></small><noframes id='n3xf1'>

    2. <legend id='n3xf1'><style id='n3xf1'><dir id='n3xf1'><q id='n3xf1'></q></dir></style></legend>

        如何在 xml 字符串中发送二进制数据

        时间:2023-06-03

        <small id='NlcfQ'></small><noframes id='NlcfQ'>

          <tfoot id='NlcfQ'></tfoot>
            <bdo id='NlcfQ'></bdo><ul id='NlcfQ'></ul>
          • <legend id='NlcfQ'><style id='NlcfQ'><dir id='NlcfQ'><q id='NlcfQ'></q></dir></style></legend>
                <tbody id='NlcfQ'></tbody>
              1. <i id='NlcfQ'><tr id='NlcfQ'><dt id='NlcfQ'><q id='NlcfQ'><span id='NlcfQ'><b id='NlcfQ'><form id='NlcfQ'><ins id='NlcfQ'></ins><ul id='NlcfQ'></ul><sub id='NlcfQ'></sub></form><legend id='NlcfQ'></legend><bdo id='NlcfQ'><pre id='NlcfQ'><center id='NlcfQ'></center></pre></bdo></b><th id='NlcfQ'></th></span></q></dt></tr></i><div id='NlcfQ'><tfoot id='NlcfQ'></tfoot><dl id='NlcfQ'><fieldset id='NlcfQ'></fieldset></dl></div>
                • 本文介绍了如何在 xml 字符串中发送二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我想以以下xml格式将二进制文件发送到.net c#组件

                  I want to send a binary file to .net c# component in the following xml format

                  <BinaryFileString fileType='pdf'>
                      <!--binary file data string here-->
                  </BinaryFileString>
                  

                  在被调用的组件中,我将使用上面的 xml 字符串并将 BinaryFileString 标记中接收到的二进制字符串转换为 filetype='' 属性指定的文件.文件类型可以是 doc/pdf/xls/rtf

                  In the called component I will use the above xml string and convert the binary string received within the BinaryFileString tag, into a file as specified by the filetype='' attribute. The file type could be doc/pdf/xls/rtf

                  我在调用应用程序中有代码从要发送的文件中取出字节.我如何准备将其与包裹在其周围的 xml 标签一起发送?我希望应用程序向组件发送一个字符串而不是字节流.这是因为我无法仅通过查看字节流来破译文件类型 [pdf/doc/xls].因此具有文件类型属性的 xml 字符串.对此有何想法?

                  I have the code in the calling application to get out the bytes from the file to be sent. How do I prepare it to be sent with xml tags wrapped around it? I want the application to send out a string to the component and not a byte stream. This is because there is no way I can decipher the file type [pdf/doc/xls] just by looking at the byte stream. Hence the xml string with the filetype attribute. Any ideas on this?

                  下面的字节提取方法

                     FileStream fs = new FileStream(_filePath, FileMode.Open, FileAccess.Read);
                     using (Stream input = fs)
                     {
                        byte[] buffer = new byte[8192];
                        int bytesRead;
                        while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
                        {}
                     }
                     return buffer;
                  

                  谢谢.

                  只是为了澄清为什么我使用 xml 字符串而不是在我的组件上设置属性.实际上,我的调用应用程序正在尝试模拟 Siebel 将如何调用我的组件.http://download.oracle.com/docs/cd/E05553_01/books/eScript/eScript_JSReference244.html#wp1014380我不确定 Siebel 是否可以根据需要设置我的组件属性.所以我正在研究它以 xml 发送数据的角度.

                  Just to clarify why I am using an xml string rather than setting properties on my component. Actually my calling app is trying to simulate how Siebel will call my component. http://download.oracle.com/docs/cd/E05553_01/books/eScript/eScript_JSReference244.html#wp1014380 Im not sure if Siebel can set my components properties as I need it to. So Im working on the angle of it sending the data in xml.

                  推荐答案

                  Base64 表示普遍用于表示二进制数据.

                  Base64 representation is universaly used to represent binary data.

                  public void EncodeWithString() {
                      System.IO.FileStream inFile;     
                      byte[] binaryData;
                  
                      try {
                          inFile = new System.IO.FileStream(inputFileName,
                                                            System.IO.FileMode.Open,
                                                            System.IO.FileAccess.Read);
                          binaryData = new Byte[inFile.Length];
                          long bytesRead = inFile.Read(binaryData, 0,
                                                      (int)inFile.Length);
                          inFile.Close();
                      }
                      catch (System.Exception exp) {
                          // Error creating stream or reading from it.
                          System.Console.WriteLine("{0}", exp.Message);
                          return;
                      }
                  
                      // Convert the binary input into Base64 UUEncoded output.
                      string base64String;
                      try {
                           base64String = 
                              System.Convert.ToBase64String(binaryData, 
                                                            0,
                                                            binaryData.Length);
                      }
                      catch (System.ArgumentNullException) {
                          System.Console.WriteLine("Binary data array is null.");
                          return;
                      }
                  
                      // Write the UUEncoded version to the XML file.
                      System.IO.StreamWriter outFile; 
                      try {
                          outFile = new System.IO.StreamWriter(outputFileName,
                                                      false,
                                                      System.Text.Encoding.ASCII);             
                          outFile.Write("<BinaryFileString fileType='pdf'>");
                          outFile.Write(base64String);
                          outFile.Write("</BinaryFileString>");
                          outFile.Close();
                      }
                      catch (System.Exception exp) {
                          // Error creating stream or writing to it.
                          System.Console.WriteLine("{0}", exp.Message);
                      }
                  }
                  

                  在接收端,您可以将其反转并取回原始文件内容,如下所述.

                  At the receiving end you can reverse this and get back original file content as mentioned below.

                          // Convert the Base64 UUEncoded input into binary output.
                          byte[] binaryData;
                          try {
                              binaryData = 
                                  System.Convert.FromBase64String(base64String);
                          }
                          catch (System.ArgumentNullException) {
                              System.Console.WriteLine("Base 64 string is null.");
                              return;
                          }
                          catch (System.FormatException) {
                              System.Console.WriteLine("Base 64 string length is not " +
                                  "4 or is not an even multiple of 4." );
                              return;
                          }
                  

                  这篇关于如何在 xml 字符串中发送二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:将base64Binary转换为pdf 下一篇:是否有格式化 64 位“无符号"的 C# 函数?值与

                  相关文章

                  最新文章

                • <i id='qERlx'><tr id='qERlx'><dt id='qERlx'><q id='qERlx'><span id='qERlx'><b id='qERlx'><form id='qERlx'><ins id='qERlx'></ins><ul id='qERlx'></ul><sub id='qERlx'></sub></form><legend id='qERlx'></legend><bdo id='qERlx'><pre id='qERlx'><center id='qERlx'></center></pre></bdo></b><th id='qERlx'></th></span></q></dt></tr></i><div id='qERlx'><tfoot id='qERlx'></tfoot><dl id='qERlx'><fieldset id='qERlx'></fieldset></dl></div>
                  <tfoot id='qERlx'></tfoot>
                    <bdo id='qERlx'></bdo><ul id='qERlx'></ul>

                  <small id='qERlx'></small><noframes id='qERlx'>

                  <legend id='qERlx'><style id='qERlx'><dir id='qERlx'><q id='qERlx'></q></dir></style></legend>