XMLPort in Webservice with Picture export

HollandPolandHollandPoland Member Posts: 62
edited 2013-06-06 in NAV Three Tier
Hello all!
I've an XMLPort with a Picture field (BLOB). I want to export the data throught a web service. But unfortunately, the C# code through an exception that the root node is not process. I've seen that the blob field is the problem. I decode it into Base64 like the function in codeunit BizTalkXMLDomMgt, but I have the problem. Is there a way to generate the xml file with XMLPort (using web service)? Thank you in advance. Regards.

Comments

  • [StaWho][StaWho] Member Posts: 3
    Hi

    WebServices won't like XMLPorts with BLOB fields, most likely because of serialization issues. The way around it, like you rightly say, is to transfer BLOBs using Base64.
    Do not include any elements with BLOB data source in your XMLPort, but instead create Text element with TextType=BigText, then fill it in with converted bytes from BLOB.

    Below code uses .NET Interop and temporary file to achieve this, but I'm sure there are ways of doing it without going through the filesystem.
    OBJECT XMLport 50005 BlobTest
    {
      OBJECT-PROPERTIES
      {
        Date=06/06/13;
        Time=10:20:09;
        Version List=;
      }
      PROPERTIES
      {
        TransactionType=Report;
        Format/Evaluate=XML Format/Evaluate;
        DefaultNamespace=urn:microsoft-dynamics-nav/xmlports/x50005;
        UseDefaultNamespace=Yes;
        UseRequestForm=Yes;
      }
      ELEMENTS
      {
        { [{90948DC4-0E6C-4B46-B18B-E6B350E0B1CB}];  ;Blob                ;Element ;Text    ;
                                                      MaxOccurs=Once }
    
        { [{EC772F8B-CFD7-4D35-A789-F047A2E53522}];1 ;CompanyInfo         ;Element ;Table   ;
                                                      VariableName=CompanyInfo;
                                                      SourceTable=Table79;
                                                      MinOccurs=Zero;
                                                      MaxOccurs=Once;
                                                      Export::OnAfterGetRecord=BEGIN
                                                                                 tempFile := Path.GetTempPath() + Path.GetRandomFileName();
                                                                                 CompanyInfo.CALCFIELDS(Picture);
                                                                                 IF CompanyInfo.Picture.HASVALUE THEN CompanyInfo.Picture.EXPORT(tempFile);
                                                                                 FileMode := 4;
                                                                                 FileAccess := 1;
                                                                                 FileStream := _File.Open(tempFile, FileMode, FileAccess);
                                                                                 MemoryStream := MemoryStream.MemoryStream();
                                                                                 MemoryStream.SetLength(FileStream.Length);
                                                                                 FileStream.Read(MemoryStream.GetBuffer(), 0, FileStream.Length);
                                                                                 Picture64.ADDTEXT(Convert.ToBase64String(MemoryStream.GetBuffer()));
                                                                                 MemoryStream.Close();
                                                                                 MemoryStream.Dispose();
                                                                                 FileStream.Close();
                                                                                 FileStream.Dispose();
                                                                                 _File.Delete(tempFile);
                                                                               END;
                                                                                }
    
        { [{150675EA-6BB1-409E-9910-23E7A8F1F949}];2 ;PostCode            ;Element ;Field   ;
                                                      DataType=Code;
                                                      SourceField=CompanyInfo::Post Code }
    
        { [{46AA84B5-B634-43DB-9D31-3792EB18AE66}];2 ;Picture64           ;Element ;Text    ;
                                                      TextType=BigText;
                                                      MaxOccurs=Once }
    
      }
      EVENTS
      {
      }
      REQUESTPAGE
      {
        PROPERTIES
        {
        }
        CONTROLS
        {
        }
      }
      CODE
      {
        VAR
          Convert@1000000007 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Convert";
          Path@1000000006 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Path";
          _File@1000000005 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.File";
          FileAccess@1000000004 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileAccess";
          FileMode@1000000003 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileMode";
          MemoryStream@1000000002 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.MemoryStream";
          FileStream@1000000001 : DotNet "'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.FileStream";
          tempFile@1000000000 : Text[250];
    
        BEGIN
        END.
      }
    }
    
    
Sign In or Register to comment.