Sometimes it’s fun just to experiment with making functions just to see if it is possible.
During one of my recent Microsoft Dynamics NAV 2009 development courses, I was challenged, if it was possible to create a webpage, where customers could print their invoices just by typing in the invoice number.
How can we do that?
- Well first we need a webservice in Microsoft Dynamics NAV 2009, created as a function in a Codeunit, which would take one parameter and return the invoice.
- Next we need to publish the webservice
- Lastly we need to create a website that utilizes the webservice, has one field and one button.
One of the challenges is: How do we get the invoice from Microsoft Dynamics NAV 2009?
I see two different solutions:
- Print the invoice as pdf on a public location and send the path back to the website as a string. Here the Website can present the pdf for download or view. The problem is, that our invoices will be available on the internet, and that is not an option, no matter how short it may live there.
- The second solution is to stream the invoice back to the website. This is a bit more complicated, but it will never compromise my data. Not to mention, that it is more funJ
So how do start?
In Microsoft Dynamics NAV 2009 I start by creating a new Codeunit: 50099 Test Web Services. In this I create one function PrintInvoice. This function takes one parameter inInvoiceNoFilter.
But how can we get the invoice back to the website as a stream?
Well we cheat.
I make another parameter called outFile with the type of BigText and make it “pass by reference”, in this way I can return values back to the website. And how do I get a pdf into a text? The answer is Base64. Base64 is a dll that can be registered on my Microsoft Dynamics NAV server, and gives you the possibility to convert a file into a string value. Where can I find it? Well check the internet, there are many free versions available.
So now my function looks like this:

I include a return value as Boolean, because we need that for webservices, and because we can signal if the function failed back to the web site.
Then to the function. First I create a number of variables:

After this I make the code:

After this has been made, I want to make a test from the RoleTailored Client
First I add two lines of code and a local variable (locOutFile is BigText) in the onRun trigger of the Codeunit:

Then add an action to the Role Center and run it. The result does not make any sense, but it will show me, that something has been made. It looks something like this:

Ok – So far so good. On to the webservice. First I need to publish my webservice in Microsoft Dynamics NAV 2009:

I name it WSFunc and to check if it has been published I check my browser:
http://<Machine Name>:<Port No>/<Instance Name>/WS/<Company Name>/Services
Remember that all spaces should be left as spaces; they will automatically be converted to %20. Some might suggest using localhost, but that might lead me into a log-on nightmare, meaning that I will need to log on all the time. Instead for testing, use the machine name and make sure that the machine is created as Local Intranet in the Internet Options’ security tab. In a live solution we talk much more security (SSL and all), that will be covered in a later post.

Ok – We’re done in Navision. Let’s go to visual Studio
First I make a new web site using the C#

In the Designer of the Default.aspx
Drag in a label, a Textbox and a button from the Toolbox, It will look something like this:

Now create a Web Reference to your webservice, sometimes you need to go through Add Service Reference then Advanced then Add Web reference:



Giving you this window where you can paste in the end point address you found in your browser. Add a reference name and click Add Reference. Do not use the same name as your webservice. C# can’t handle that namespaces and variables have the same name.

After this you can see the Web Reference in the solution explorer:

Now on to the code lines:
In the Designer, double click the button. That will take you to the code:
In the top include the Web Reference

Now to the code:

Press F5 to test the page, Type an known invoice No in the Text field and Click the Button. It should look like this:

After Clicking the Button:

And here you go.
Have fun.
Wah, NH88hlink lagi! Okay juga, banyak game baru. Semoga kali ini gacor lah. nh88hlink
Goldenhoyeah1’s got a certain charm to it, you know? The graphics are pretty decent, and the games are easy to pick up. Good for a casual gaming session. Feel like a fun time? Give it a shot: goldenhoyeah1
188BET got blocked again? No worries! linkvao188betmoinhat always has the latest working links. Saves me every time. Get in the game using linkvao188betmoinhat
I am genuinely grateful to the owner of this website who has shared this impressive paragraph at at this time.
Excellent post. I used to be checking constantly this blog and I am inspired! Extremely helpful info specially the closing part 🙂 I maintain such info much. I used to be looking for this particular information for a long time. Thanks and good luck.
Great article.
Keep working ,impressive job!
It’s remarkable in favor of me to have a site, which is beneficial for my know-how. thanks admin
Very good site you have here but I was wondering if you knew of any discussion boards that cover the same topics talked about here? I’d really love to be a part of group where I can get suggestions from other experienced people that share the same interest. If you have any recommendations, please let me know. Bless you!
Hello, i think that i saw you visited my blog so i came to “return the favor”.I am trying to find things to improve my web site!I suppose its ok to use a few of your ideas!!
Hmm is anyone else experiencing problems with the images on this blog loading? I’m trying to determine if its a problem on my end or if it’s the blog. Any responses would be greatly appreciated.
Whats up are using WordPress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any html coding expertise to make your own blog? Any help would be really appreciated!
Amazing issues here. I am very happy to look your article. Thanks a lot and I’m taking a look forward to contact you. Will you kindly drop me a mail?
If you would like to improve your know-how only keep visiting this site and be updated with the hottest news update posted here.
I like the valuable info you supply to your articles. I will bookmark your weblog and take a look at once more here frequently. I am moderately certain I’ll be told plenty of new stuff proper right here! Good luck for the next!
obviously like your web-site however you have to take a look at the spelling on several of your posts. Several of them are rife with spelling issues and I in finding it very troublesome to inform the truth nevertheless I’ll definitely come again again.
I have read some excellent stuff here. Definitely price bookmarking for revisiting. I surprise how much attempt you put to create this sort of excellent informative website.
whoah this weblog is magnificent i really like studying your posts. Stay up the good work! You realize, lots of persons are searching around for this information, you could help them greatly.
Hey I am so excited I found your website, I really found you by error, while I was looking on Askjeeve for something else, Anyhow I am here now and would just like to say thanks for a marvelous post and a all round enjoyable blog (I also love the theme/design), I don’t have time to look over it all at the minute but I have bookmarked it and also added in your RSS feeds, so when I have time I will be back to read more, Please do keep up the fantastic work.
Great content! Super high-quality! Keep it up!
Wonderful items from you, man. I have take note your stuff prior to and you are just too great. I actually like what you have acquired right here, certainly like what you are saying and the best way during which you assert it. You are making it enjoyable and you still care for to stay it wise. I cant wait to read much more from you. This is actually a terrific site.
I’m so in love with this. You did a great job!!
When someone writes an piece of writing he/she keeps the plan of a user in his/her brain that how a user can be aware of it. So that’s why this paragraph is outstdanding. Thanks!
Please tell me more about this. May I ask you a question?
Thank you for your articles. They are very helpful to me. May I ask you a question?
Thank you for writing this post!
Great content! Super high-quality! Keep it up!
How can I find out more about it?