cant consume NAV Web Service in C#.

Majestic
Member Posts: 10
IM new on this forum, so bare with me if i posted this in the wrong forum.
Here goes...
I have been trying all sorts of ways to consume this web-service i have been given. Ill try and show you what i do to get where i am atm.
1. i start by adding the service reference in VS. everything goes as intended, i can see all the methods given to me.
2. to access the methods, and hopefully get some data, i do the following:
i get the following error: HTTP-status 401: Unauthorized.
I can say that the service i consume have a bunch of methods, only one method return a string, rest return void. the method that returns a string is working perfectly, but the "void" methods are not, im abit confused about that, so if anyone could shet some light on this i would get really happy.
any help would be much apreciated, since im kinda stuck
regards Majestic
Here goes...
I have been trying all sorts of ways to consume this web-service i have been given. Ill try and show you what i do to get where i am atm.
1. i start by adding the service reference in VS. everything goes as intended, i can see all the methods given to me.
2. to access the methods, and hopefully get some data, i do the following:
BMGWS ws = new BMGWS(); Vogn vogn = new Vogn(); VognType ty = new VognType(); NetworkCredential cred = new NetworkCredential("username","Password","domain"); ws.PreAuthenticate = true; ws.Credentials= cred; ws.SendVogn("BMG 2013", true, ref vogn); foreach (VognType c in vogn.Vogn1) { Console.WriteLine(c.RegNr); }
i get the following error: HTTP-status 401: Unauthorized.
I can say that the service i consume have a bunch of methods, only one method return a string, rest return void. the method that returns a string is working perfectly, but the "void" methods are not, im abit confused about that, so if anyone could shet some light on this i would get really happy.
any help would be much apreciated, since im kinda stuck
regards Majestic
0
Answers
-
Did you expose your Webservice correctly? Can you access it in IE?
How does the URL look like that you added as Web-Reference?
Do you mind just trying ws.usedefaultcredentials = true?Austrian NAV/BC Dev0 -
Wisa123 wrote:Did you expose your Webservice correctly? Can you access it in IE?
How does the URL look like that you added as Web-Reference?
Do you mind just trying ws.usedefaultcredentials = true?
i added a webservice by right clicking on my solution and chose "add webservice", and clicking advanced and adding a web referernce.
thereafter i get alot of services/methods added that i can use, as i explain above, there is only one method that sends somthing in return, my checkLogin method gives me a string in return if its a correct login that has been parsed. the other methods returns void eg nothing, that is confuesing to me.
Anyhow i tried what you said about the "ws.usedefaultcredentials = true" and it seems like it works with my login method. but does still not work with the rest of the methods.
my code atm looks like this:ws = new BMGWS(); Vogn vogn = new Vogn(); ws.UseDefaultCredentials = true; ws.Url = "http:// adress:port/BMGLIGHT2013/WS/Admin/Codeunit/BMGWS"; string s = ws.CheckLogin("string", "string", int); Console.WriteLine(s); ws.SendVogn("CRONUS AS", true, ref vogn); foreach (VognType c in vogn.Vogn1) { Console.WriteLine(c.RegNr.ToString()); } Console.ReadLine();
my checklogin() works well, tho my ws.sendvogn() does not :-k - Its supposed to send me some 3 tables of data from NAV
At the moment i dont get any errors when building, but i get absolutly nothing in return from NAV.
If i add the service without adding it as a web reference, but as a normal Service refernce, i cant get my loginmethod to work... i get the error: The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'NTLM’
i use this code for my normal service reference:BMGWS_PortClient ws = new BMGWS_PortClient(); Vogn vogn = new Vogn(); NetworkCredential cred = new NetworkCredential("Username", "Password", "domain"); ws.ClientCredentials.Windows.ClientCredential = cred; string s = ws.CheckLogin("string", "string", int); Console.WriteLine(s);
hope you can help!0 -
and yes, i can access it in internet explore
here is the XML of the SendVogn:<element name="SendVogn"> <complexType> <sequence> <element minOccurs="1" maxOccurs="1" name="comp" type="string"/> <element minOccurs="1" maxOccurs="1" name="inaktiv" type="boolean"/> <element minOccurs="1" maxOccurs="1" name="bMGVogn" type="q4:Vogn"/> </sequence> </complexType> </element>
0 -
I have solvedmy problem! the fix was:
ws.SendVogn("BMG 2013", true, ref vogn);
there was no test data in the database with the Bool value true, changed it to false and it worked, my working code looks like this:BMGWS ws = new BMGWS(); Vogn vogn = new Vogn(); ws.UseDefaultCredentials = true; Console.ReadKey(); ws.SendVogn("BMG 2013", false, ref vogn); foreach (VognType c in vogn.Vogn1) { Console.WriteLine(); Console.WriteLine(c.Beskrivelse); Console.WriteLine(c.Kode); Console.WriteLine(c.RegNr); Console.WriteLine(c.Spaerret); Console.WriteLine(); }
it works perfectly!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions