SHOW:
|
|
- or go back to the newest paste.
1 | internal class Program | |
2 | { | |
3 | private static void Main(string[] args) | |
4 | { | |
5 | baseService = new BaseService(); | |
6 | dmsService = new DmsService(); | |
7 | ||
8 | - | baseService.CookieContainer = new System.Net.CookieContainer(); |
8 | + | baseService.CookieContainer = new System.Net.CookieContainer(); // -- neu -- |
9 | dmsService.CookieContainer = new System.Net.CookieContainer(); | |
10 | ||
11 | // -- TESTS -- | |
12 | ||
13 | SetWebserviceRootUrl("https://demo.computech.de/schulung/"); | |
14 | username = "mhermsen"; | |
15 | password = "12345"; | |
16 | ||
17 | Console.WriteLine(GetTemplates()); | |
18 | ||
19 | SetWebserviceRootUrl("http://192.168.200.122:8500/CoBRA/_web"); | |
20 | username = "admin"; | |
21 | password = "admin"; | |
22 | ||
23 | Console.WriteLine(GetTemplates()); | |
24 | ||
25 | SetWebserviceRootUrl("https://demo.computech.de/schulung/"); | |
26 | username = "mhermsen"; | |
27 | password = "12345"; | |
28 | ||
29 | Console.WriteLine(GetTemplates()); | |
30 | ||
31 | Console.ReadLine(); | |
32 | } | |
33 | ||
34 | private static BaseService baseService; | |
35 | private static DmsService dmsService; | |
36 | private static string username; | |
37 | private static string password; | |
38 | ||
39 | private static void SetWebserviceRootUrl(string rootUrl) | |
40 | { | |
41 | try | |
42 | { | |
43 | baseService.Url = $"{rootUrl}/svc/cobra.cfc?wsdl"; | |
44 | dmsService.Url = $"{rootUrl}/svc/dms.cfc?wsdl"; | |
45 | } | |
46 | catch (Exception e) | |
47 | { | |
48 | Console.WriteLine(e); | |
49 | } | |
50 | } | |
51 | ||
52 | private static bool Login() | |
53 | { | |
54 | try | |
55 | { | |
56 | Base.ResultVoid loginResult = baseService.loginUser(username, password); | |
57 | double? loginErrorCode = loginResult.errorCode; | |
58 | ||
59 | if (loginErrorCode != 3) | |
60 | { | |
61 | - | dmsService.CookieContainer = baseService.CookieContainer; |
61 | + | dmsService.CookieContainer = baseService.CookieContainer; // Bei einem erfolgreichen Login den Cookie Container vom Baseservice übernehmen |
62 | return true; | |
63 | } | |
64 | ||
65 | return false; | |
66 | } | |
67 | catch (Exception e) | |
68 | { | |
69 | Console.WriteLine(e); | |
70 | return false; | |
71 | } | |
72 | } | |
73 | ||
74 | private static bool CheckSession(int errorCode) | |
75 | { | |
76 | return errorCode != 3 || Login(); | |
77 | } | |
78 | ||
79 | private static string GetTemplates() | |
80 | { | |
81 | DMS.ResultQuery response = dmsService.getTemplates(); | |
82 | ||
83 | if (response.errorCode == 3) | |
84 | { | |
85 | if (CheckSession((int)response.errorCode)) | |
86 | { | |
87 | response = dmsService.getTemplates(); | |
88 | } | |
89 | else | |
90 | { | |
91 | throw new Exception("Login fehlgeschlagen"); | |
92 | } | |
93 | } | |
94 | ||
95 | if (response.errorCode == 0) | |
96 | { | |
97 | DMS.QueryBean result = response.result; | |
98 | ||
99 | return "die templates vom dms service ..."; | |
100 | } | |
101 | ||
102 | throw new Exception(response.errorMsg); | |
103 | } | |
104 | } |