Skip to content

Webservice with XMLPorts (Performance)

January 4, 2011

In a customer project we had to deal with webservices that had to offer large amount of data. To acomplish that we used NAV webservices in combination with xmlports. becaus the dataload was so havy we were facing a lot of problems in performance.

an example: a response to ws-request about 50sec for a average load of data (pure text about 500kb).

After a lot of investigation and testing i learned several things about webservices in NAV in combination with XMLPorts and BigText Variables.

To expose data trough a function in a Codeunit you have 2 joices. You can either do it with a xmlport or a bigtextvar. You should always go for the xmlport because in .Net you have all your datastructure perfectly designed with classes and Members. If you do it with the BigText you just have a string of xml.

But now to the performace part:

BigText Var

If your supported languages are using special characters (like ä,ö,ü) you need to do special operations if you are using BigTextVar. There are problems in NAV when you are reading out of a stream these special characters from UTF-8 & UTF-16 Format. Because of that you need to convert them with the NAV built in ANSI2ASCII method. This works only in UTF-16!

I tried to find the best code to do that and eneded up with this:

Counter := 0;
REPEAT Counter += 1;
  TotalLen := 0;
  CLEAR(TempText);
  REPEAT ActLen := IStream.READ(TempText2,MAXSTRLEN(TempText));
    IF ActLen 0 THEN BEGIN
      TotalLen += ActLen;
      TempText += TempText2;
    END;
  UNTIL (ActLen = 0) OR (TotalLen = MAXSTRLEN(TempText));
  TempText := GeneralMgt.Ansi2Ascii(TempText);</code>
  // Search Beginning (UTF-16  related)
  IF Counter = 1 THEN
    TempText :=  COPYSTR(TempText,STRPOS(TempText,'<'));
  OutputXML.ADDTEXT(TempText,OutputXML.LENGTH+1);
UNTIL (ActLen = 0);

With this you can ensure you get correct encoded characters. Because with UTF-16 only one char is read each time you call the READ function, you need to loop that and then convert from ansi2ascii, this is more performant.

Freddy had a good article about importing/exporting problems with special characters in NAV2009. I haven’t tried it but i think it would be possible to convert the incorrect text strings in the consuming application with this code.

XMLPort

If you stick with the exposed xmlport (paramter in function as VAR) you can run in into performance problems if you use not accurate keys. so ensure you have good keys! Even if your xmlport runs fast in classic, in NST it will probably not! So double-check that!

when you write your code for the xmlport (filtering, etc) don’t call the EXPORT function! You don’t have to! the webservice engine does it by itself, if you call it by code, the execution time gets doubled because you call it and the WS does the same!

If you have complex data structure, it is sometimes better do filtering / DataItem linking by code! try that if you have performance issues.

Advertisements

From → C# .NET, Dynamics NAV

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s