![]() |
#1 |
Участник
|
Some time ago, I did a session at Direction EMEA in Berlin. Apparently, some people were inspired with this. Not only did I introduce "cannibalism" (never expected this to be something "hot, new and inspiring" but rather something "obvious" - let's spend a blogpost on that as well..
![]() In fact, you can see this as "consuming a third party web service". There are tons of those out there .. and this example is quite useful, if you ask me (more useful than getting the weather info, or a list of songs of a certain genre, is it.. ;° ![]() What Web Service? A functional consultant pointed me to a certain official webservice that had some promising capabilities. This is the website that uses that same webservice: http://ec.europa.eu/taxation_customs/vies/ As you can see, you can validate the VAT Number in quite some European countries. This is something customers definitely want .. so what if we could build such a functionality in NAV. We would need a web service, right? Well, here it is, just for free: http://ec.europa.eu/taxation_customs...atService.wsdl Basically, using this web service, is kind of the same way as using any web service - so also quite the same as I described in this blogpost: NAV 2009 R2 .Net Interop: Calling a Web Service (come to think of it - I can make this blog quite short and let's share the objects I created here). Building the Proxy This will take the majority of your time - at least 2 minutes (because Visual Studio doesn't load very fast). I'm not going to create a service reference, but a web reference.
![]() As I mentioned, I'm going to use a web reference, so let's click Advanced / Add Web Reference and provide the url I mentioned above. Give it a proper name (I used "VATValidationService") and click "Add Reference": ![]() That's it, people! Build you're solution and get the hell out of Visual Studio! Deploy You're safe now .. you're almost back in you familiar habitat (we like to call C/AL). Just first copy the dll (which is the proxy class you'll need in NAV) to your classic client and server:
Use Let's go to nav and write some very simple code there - it's not functional in any way, it's just a test-codeunit that uses the service. You can build the business logic any way you like. First declare some variables: Name DataType Subtype Length CheckVATService DotNet 'VATValidation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.VATValidation.VATValidationService.checkVatService CountryCode Code 10 VATNumber Text 1024 Name Text 1024 Address Text 1024 Success Boolean Then, OnRun, I wrote these lines of code: CheckVATService := CheckVATService.checkVatService(); //the constructor CountryCode := 'BE'; VATNumber := '0885815777'; //VATNumber := '0863844386'; //VATNumber := '0891609053'; CheckVATService.checkVat(CountryCode,VATNumber,Success,Name,Address); IF Success THEN MESSAGE(Name + '' + Address) ELSE MESSAGE('No Success'); I agree, the business logic is not useable at all .. but that was not the intention. I just provided you the way to use the CheckVat function .. and now it's up to you. The Download The download contains my test-objects from my demo-db. Take them "as is" .. so if you want to implement this at a customer, do that on your own risk - and reconsider the code (make it "partner ready" :-) ). The download contains:
Читать дальше
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|