-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWsdl.cs
857 lines (810 loc) · 33.8 KB
/
Wsdl.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Web.Services;
using System.Web.Services.Description;
using System.Web.Services.Discovery;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Security.Cryptography.X509Certificates;
using WebServiceStudio.Dialogs;
namespace WebServiceStudio
{
internal class Wsdl
{
private bool cancelled = false;
private CodeDomProvider compiler = null;
private CodeCompileUnit compileUnit;
private static string duplicateSchema = "Warning: Ignoring duplicate schema description with TargetNamespace='{0}' from '{1}'.";
private static string duplicateService = "Warning: Ignoring duplicate service description with TargetNamespace='{0}' from '{1}'.";
private StringCollection paths = new StringCollection();
private Assembly proxyAssembly;
private string proxyCode = "<NOT YET>";
private string proxyNamespace = "";
private static string schemaValidationFailure = "Schema could not be validated. Class generation may fail or may produce incorrect results";
private StringCollection wsdls = new StringCollection();
private StringCollection xsds = new StringCollection();
private void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions)
{
ServiceDescription serviceDescription = document as ServiceDescription;
if (serviceDescription != null)
{
if (descriptions[serviceDescription.TargetNamespace] == null)
{
descriptions.Add(serviceDescription);
StringWriter w = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(w);
writer.Formatting = Formatting.Indented;
serviceDescription.Write(writer);
this.wsdls.Add(w.ToString());
}
else
{
this.CheckPoint(MessageType.Warning, string.Format(duplicateService, serviceDescription.TargetNamespace, path));
}
}
else
{
XmlSchema schema = document as XmlSchema;
if (schema != null)
{
if (schemas[schema.TargetNamespace] == null)
{
schemas.Add(schema);
StringWriter writer3 = new StringWriter();
XmlTextWriter writer4 = new XmlTextWriter(writer3);
writer4.Formatting = Formatting.Indented;
schema.Write(writer4);
this.xsds.Add(writer3.ToString());
}
else
{
this.CheckPoint(MessageType.Warning, string.Format(duplicateSchema, serviceDescription.TargetNamespace, path));
}
}
}
}
private static void AddElementAndType(XmlSchema schema, string baseXsdType, string ns)
{
XmlSchemaElement item = new XmlSchemaElement();
item.Name = baseXsdType;
item.SchemaTypeName = new XmlQualifiedName(baseXsdType, ns);
schema.Items.Add(item);
XmlSchemaComplexType type = new XmlSchemaComplexType();
type.Name = baseXsdType;
XmlSchemaSimpleContent content = new XmlSchemaSimpleContent();
type.ContentModel = content;
XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();
extension.BaseTypeName = new XmlQualifiedName(baseXsdType, "http://www.w3.org/2001/XMLSchema");
content.Content = extension;
schema.Items.Add(type);
}
private static void AddFakeSchemas(XmlSchema parent, XmlSchemas schemas)
{
if (schemas["http://www.w3.org/2001/XMLSchema"] == null)
{
XmlSchemaImport item = new XmlSchemaImport();
item.Namespace = "http://www.w3.org/2001/XMLSchema";
item.Schema = CreateFakeXsdSchema("http://www.w3.org/2001/XMLSchema", "schema");
parent.Includes.Add(item);
}
if (schemas["http://schemas.xmlsoap.org/soap/encoding/"] == null)
{
XmlSchemaImport import2 = new XmlSchemaImport();
import2.Namespace = "http://schemas.xmlsoap.org/soap/encoding/";
import2.Schema = CreateFakeSoapEncodingSchema("http://schemas.xmlsoap.org/soap/encoding/", "Array");
parent.Includes.Add(import2);
}
if (schemas["http://schemas.xmlsoap.org/wsdl/"] == null)
{
XmlSchemaImport import3 = new XmlSchemaImport();
import3.Namespace = "http://schemas.xmlsoap.org/wsdl/";
import3.Schema = CreateFakeWsdlSchema("http://schemas.xmlsoap.org/wsdl/");
parent.Includes.Add(import3);
}
}
private static void AddSimpleType(XmlSchema schema, string typeName, string baseXsdType)
{
XmlSchemaSimpleType item = new XmlSchemaSimpleType();
item.Name = typeName;
XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction();
restriction.BaseTypeName = new XmlQualifiedName(baseXsdType, "http://www.w3.org/2001/XMLSchema");
item.Content = restriction;
schema.Items.Add(item);
}
public void Cancel()
{
this.cancelled = true;
}
private void ChangeBaseType(CodeCompileUnit compileUnit)
{
if ((this.WsdlProperties.ProxyBaseType != null) && (this.WsdlProperties.ProxyBaseType.Length != 0))
{
Type type = Type.GetType(this.WsdlProperties.ProxyBaseType, true);
foreach (CodeNamespace namespace2 in compileUnit.Namespaces)
{
foreach (CodeTypeDeclaration declaration in namespace2.Types)
{
bool flag = false;
foreach (CodeAttributeDeclaration declaration2 in declaration.CustomAttributes)
{
if (declaration2.Name == typeof(WebServiceBindingAttribute).FullName)
{
flag = true;
break;
}
}
if (flag)
{
declaration.BaseTypes[0] = new CodeTypeReference(type.FullName);
}
}
}
}
}
private void CheckPoint(MessageType status, string message)
{
if (!this.cancelled)
{
NewMainForm.ShowMessage(this, status, message);
}
}
private static void CollectIncludes(XmlSchema schema, Hashtable includeSchemas)
{
XmlSchemaObjectEnumerator enumerator = schema.Includes.GetEnumerator();
while (enumerator.MoveNext())
{
XmlSchemaExternal current = (XmlSchemaExternal)enumerator.Current;
string schemaLocation = current.SchemaLocation;
if (current is XmlSchemaImport)
{
current.SchemaLocation = null;
}
else if (((current is XmlSchemaInclude) && (schemaLocation != null)) && (schemaLocation.Length > 0))
{
string str2 = Path.GetFullPath(schemaLocation).ToLower();
if (includeSchemas[str2] == null)
{
XmlSchema schema2 = ReadSchema(schemaLocation);
includeSchemas[str2] = schema2;
CollectIncludes(schema2, includeSchemas);
}
current.Schema = (XmlSchema)includeSchemas[str2];
current.SchemaLocation = null;
}
}
}
private void Compile(XmlSchemas userSchemas)
{
XmlSchema parent = new XmlSchema();
foreach (XmlSchema schema2 in userSchemas)
{
if ((schema2.TargetNamespace != null) && (schema2.TargetNamespace.Length == 0))
{
schema2.TargetNamespace = null;
}
if (schema2.TargetNamespace == parent.TargetNamespace)
{
XmlSchemaInclude item = new XmlSchemaInclude();
item.Schema = schema2;
parent.Includes.Add(item);
}
else
{
XmlSchemaImport import = new XmlSchemaImport();
import.Namespace = schema2.TargetNamespace;
import.Schema = schema2;
parent.Includes.Add(import);
}
}
AddFakeSchemas(parent, userSchemas);
try
{
//XmlSchemaCollection schemas = new XmlSchemaCollection();
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallbackWithErrorCode);
schemas.Add(parent);
if (schemas.Count == 0)
{
this.CheckPoint(MessageType.Warning, schemaValidationFailure);
}
}
catch (Exception exception)
{
this.CheckPoint(MessageType.Warning, schemaValidationFailure + "\n" + exception.Message);
}
}
private CodeDomProvider CreateCodeGenerator()
{
Language language = this.WsdlProperties.Language;
switch (language)
{
case Language.CS:
this.compiler = new CSharpCodeProvider();
break;
case Language.VB:
this.compiler = new VBCodeProvider();
break;
default:
{
if (language != Language.Custom)
{
throw new Exception("Unknown language");
}
Type type = Type.GetType(this.WsdlProperties.CustomCodeDomProvider);
if (type == null)
{
throw new TypeLoadException("Type '" + this.WsdlProperties.CustomCodeDomProvider + "' is not found");
}
this.compiler = (CodeDomProvider)Activator.CreateInstance(type);
break;
}
}
return compiler;
}
private DiscoveryClientProtocol CreateDiscoveryClient()
{
DiscoveryClientProtocol protocol = new DiscoveryClientProtocol();
protocol.AllowAutoRedirect = true;
if ((this.WsdlProperties.UserName != null) && (this.WsdlProperties.UserName.Length != 0))
{
protocol.Credentials = new NetworkCredential(this.WsdlProperties.UserName, this.WsdlProperties.Password, this.WsdlProperties.Domain);
}
else
{
protocol.Credentials = CredentialCache.DefaultCredentials;
}
if (this.WsdlProperties.UseClientCert)
{
X509Certificate2 cert = GetClientCert();
if (cert != null)
{
protocol.ClientCertificates.Add(cert);
}
}
if ((this.WsdlProperties.ProxyServer != null) && (this.WsdlProperties.ProxyServer.Length != 0))
{
IWebProxy proxy = null;
proxy = new WebProxy(this.WsdlProperties.ProxyServer);
proxy.Credentials = new NetworkCredential(this.WsdlProperties.ProxyUserName, this.WsdlProperties.ProxyPassword, this.WsdlProperties.ProxyDomain);
protocol.Proxy = proxy;
}
return protocol;
}
private X509Certificate2 GetClientCert()
{
X509Store certStore = new X509Store(StoreLocation.CurrentUser);
certStore.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
X509Certificate2Collection selectedCerts = X509Certificate2UI.SelectFromCollection(certStore.Certificates, "Select a certificate", "Please select the client certificate you would like to use", X509SelectionFlag.SingleSelection);
certStore.Close();
if (selectedCerts.Count > 0)
{
return selectedCerts[0];
}
return null;
}
private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name)
{
XmlSchema schema = new XmlSchema();
schema.TargetNamespace = ns;
XmlSchemaGroup item = new XmlSchemaGroup();
item.Name = "Array";
XmlSchemaSequence sequence = new XmlSchemaSequence();
XmlSchemaAny any = new XmlSchemaAny();
any.MinOccurs = 0M;
any.MaxOccurs = 79228162514264337593543950335M;
sequence.Items.Add(any);
any.Namespace = "##any";
any.ProcessContents = XmlSchemaContentProcessing.Lax;
item.Particle = sequence;
schema.Items.Add(item);
XmlSchemaComplexType type = new XmlSchemaComplexType();
type.Name = name;
XmlSchemaGroupRef ref2 = new XmlSchemaGroupRef();
ref2.RefName = new XmlQualifiedName("Array", ns);
type.Particle = ref2;
XmlSchemaAttribute attribute = new XmlSchemaAttribute();
attribute.RefName = new XmlQualifiedName("arrayType", ns);
type.Attributes.Add(attribute);
schema.Items.Add(type);
attribute = new XmlSchemaAttribute();
attribute.Use = XmlSchemaUse.None;
attribute.Name = "arrayType";
schema.Items.Add(attribute);
AddSimpleType(schema, "base64", "base64Binary");
AddElementAndType(schema, "anyURI", ns);
AddElementAndType(schema, "base64Binary", ns);
AddElementAndType(schema, "boolean", ns);
AddElementAndType(schema, "byte", ns);
AddElementAndType(schema, "date", ns);
AddElementAndType(schema, "dateTime", ns);
AddElementAndType(schema, "decimal", ns);
AddElementAndType(schema, "double", ns);
AddElementAndType(schema, "duration", ns);
AddElementAndType(schema, "ENTITIES", ns);
AddElementAndType(schema, "ENTITY", ns);
AddElementAndType(schema, "float", ns);
AddElementAndType(schema, "gDay", ns);
AddElementAndType(schema, "gMonth", ns);
AddElementAndType(schema, "gMonthDay", ns);
AddElementAndType(schema, "gYear", ns);
AddElementAndType(schema, "gYearMonth", ns);
AddElementAndType(schema, "hexBinary", ns);
AddElementAndType(schema, "ID", ns);
AddElementAndType(schema, "IDREF", ns);
AddElementAndType(schema, "IDREFS", ns);
AddElementAndType(schema, "int", ns);
AddElementAndType(schema, "integer", ns);
AddElementAndType(schema, "language", ns);
AddElementAndType(schema, "long", ns);
AddElementAndType(schema, "Name", ns);
AddElementAndType(schema, "NCName", ns);
AddElementAndType(schema, "negativeInteger", ns);
AddElementAndType(schema, "NMTOKEN", ns);
AddElementAndType(schema, "NMTOKENS", ns);
AddElementAndType(schema, "nonNegativeInteger", ns);
AddElementAndType(schema, "nonPositiveInteger", ns);
AddElementAndType(schema, "normalizedString", ns);
AddElementAndType(schema, "positiveInteger", ns);
AddElementAndType(schema, "QName", ns);
AddElementAndType(schema, "short", ns);
AddElementAndType(schema, "string", ns);
AddElementAndType(schema, "time", ns);
AddElementAndType(schema, "token", ns);
AddElementAndType(schema, "unsignedByte", ns);
AddElementAndType(schema, "unsignedInt", ns);
AddElementAndType(schema, "unsignedLong", ns);
AddElementAndType(schema, "unsignedShort", ns);
return schema;
}
private static XmlSchema CreateFakeWsdlSchema(string ns)
{
XmlSchema schema = new XmlSchema();
schema.TargetNamespace = ns;
XmlSchemaAttribute item = new XmlSchemaAttribute();
item.Use = XmlSchemaUse.None;
item.Name = "arrayType";
item.SchemaTypeName = new XmlQualifiedName("QName", "http://www.w3.org/2001/XMLSchema");
schema.Items.Add(item);
return schema;
}
private static XmlSchema CreateFakeXsdSchema(string ns, string name)
{
XmlSchema schema = new XmlSchema();
schema.TargetNamespace = ns;
XmlSchemaElement item = new XmlSchemaElement();
item.Name = name;
XmlSchemaComplexType type = new XmlSchemaComplexType();
item.SchemaType = type;
schema.Items.Add(item);
return schema;
}
private static bool FileExists(string path)
{
bool flag = false;
if ((path == null) || (path.Length == 0))
{
return false;
}
try
{
flag = (path.LastIndexOf('?') == -1) && System.IO.File.Exists(path);
}
catch
{
}
return flag;
}
public void Generate()
{
this.CheckPoint(MessageType.Begin, "Initializing");
ServiceDescriptionCollection descriptions = new ServiceDescriptionCollection();
XmlSchemas schemas = new XmlSchemas();
StringCollection urls = new StringCollection();
StringCollection localPaths = new StringCollection();
this.GetPaths(localPaths, urls);
descriptions.Clear();
schemas.Clear();
if ((localPaths != null) && (localPaths.Count > 0))
{
string path = localPaths[0];
string extension = Path.GetExtension(path);
if ((string.Compare(extension, ".exe", true) == 0) || (string.Compare(extension, ".dll", true) == 0))
{
this.CheckPoint(MessageType.Begin, "Loading Assembly");
this.proxyAssembly = Assembly.LoadFrom(path);
if (this.proxyAssembly != null)
{
this.CheckPoint(MessageType.Success, "Loaded Assembly");
}
else
{
this.CheckPoint(MessageType.Failure, "Failed to load Assembly");
}
return;
}
}
this.CheckPoint(MessageType.Begin, "Generating WSDL");
try
{
DiscoveryClientProtocol client = this.CreateDiscoveryClient();
this.ProcessLocalPaths(client, localPaths, schemas, descriptions);
this.ProcessRemoteUrls(client, urls, schemas, descriptions);
}
catch (Exception exception)
{
this.CheckPoint(MessageType.Failure, exception.ToString());
return;
}
try
{
this.CheckPoint(MessageType.Begin, "Generating Proxy");
this.CreateCodeGenerator();
XmlSchemas userSchemas = new XmlSchemas();
userSchemas.Add(schemas);
foreach (ServiceDescription description in descriptions)
{
userSchemas.Add(description.Types.Schemas);
}
Hashtable includeSchemas = new Hashtable();
foreach (XmlSchema schema in userSchemas)
{
CollectIncludes(schema, includeSchemas);
}
this.Compile(userSchemas);
this.GenerateCode(descriptions, schemas, "http://tempuri.org");
this.CheckPoint(MessageType.Begin, "Compiling Proxy");
this.GenerateAssembly();
this.CheckPoint(MessageType.Success, "Generated Assembly");
}
catch (Exception exception2)
{
this.CheckPoint(MessageType.Failure, exception2.ToString());
}
}
private void GenerateAssembly()
{
CreateCodeGenerator();
string location = string.Empty;
if ((this.WsdlProperties.ProxyBaseType != null) && (this.WsdlProperties.ProxyBaseType.Length > 0))
{
location = Type.GetType(this.WsdlProperties.ProxyBaseType, true).Assembly.Location;
}
string[] assemblyNames = new string[] { "System.Xml.dll", "System.dll", "System.Web.Services.dll", "System.Data.dll", Assembly.GetExecutingAssembly().Location, location };
CompilerParameters options = new CompilerParameters(assemblyNames);
options.WarningLevel = 0;
options.GenerateInMemory = false;
CompilerResults results = compiler.CompileAssemblyFromSource(options, this.proxyCode);
if (results.Errors.HasErrors)
{
foreach (CompilerError error in results.Errors)
{
this.CheckPoint(MessageType.Error, error.ToString());
}
throw new Exception("CompilationErrors");
}
this.proxyAssembly = results.CompiledAssembly;
}
private void GenerateCode(ServiceDescriptionCollection sources, XmlSchemas schemas, string uriToWSDL)
{
this.proxyCode = " <ERROR> ";
StringWriter w = null;
this.compileUnit = new CodeCompileUnit();
ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
importer.Schemas.Add(schemas);
foreach (ServiceDescription description in sources)
{
importer.AddServiceDescription(description, "", "");
}
importer.Style = ServiceDescriptionImportStyle.Client;
Protocol protocol = this.WsdlProperties.Protocol;
importer.ProtocolName = this.WsdlProperties.Protocol.ToString();
CodeNamespace namespace2 = new CodeNamespace(this.proxyNamespace);
this.compileUnit.Namespaces.Add(namespace2);
ServiceDescriptionImportWarnings warnings = importer.Import(namespace2, this.compileUnit);
try
{
try
{
w = new StringWriter();
}
catch
{
throw;
}
MemoryStream stream = null;
if (schemas.Count > 0)
{
this.compileUnit.ReferencedAssemblies.Add("System.Data.dll");
foreach (XmlSchema schema in schemas)
{
string targetNamespace = null;
try
{
targetNamespace = schema.TargetNamespace;
if (XmlSchemas.IsDataSet(schema))
{
if (stream == null)
{
stream = new MemoryStream();
}
stream.Position = 0L;
stream.SetLength(0L);
schema.Write(stream);
stream.Position = 0L;
DataSet dataSet = new DataSet();
dataSet.ReadXmlSchema(stream);
System.Data.Design.TypedDataSetGenerator.Generate(dataSet, namespace2, compiler);
}
continue;
}
catch
{
throw;
}
}
}
try
{
GenerateVersionComment(this.compileUnit.Namespaces[0]);
this.ChangeBaseType(this.compileUnit);
compiler.GenerateCodeFromCompileUnit(this.compileUnit, w, null);
}
catch (Exception exception)
{
if (w != null)
{
w.Write("Exception in generating code");
w.Write(exception.Message);
}
throw new InvalidOperationException("Error generating ", exception);
}
}
finally
{
this.proxyCode = w.ToString();
if (w != null)
{
w.Close();
}
}
}
private static void GenerateVersionComment(CodeNamespace codeNamespace)
{
codeNamespace.Comments.Add(new CodeCommentStatement(""));
AssemblyName name = Assembly.GetExecutingAssembly().GetName();
Version version = Environment.Version;
codeNamespace.Comments.Add(new CodeCommentStatement("Assembly " + name.Name + " Version = " + version.ToString()));
codeNamespace.Comments.Add(new CodeCommentStatement(""));
}
public CodeDomProvider GetCodeGenerator
{
get
{
return CreateCodeGenerator();
}
}
private void GetPaths(StringCollection localPaths, StringCollection urls)
{
StringEnumerator enumerator = this.paths.GetEnumerator();
while (enumerator.MoveNext())
{
string current = enumerator.Current;
if (FileExists(current))
{
if (!Path.HasExtension(current))
{
throw new InvalidOperationException(current + " has no extensions");
}
localPaths.Add(current);
}
else
{
Uri uri = null;
try
{
uri = new Uri(current);
}
catch (Exception)
{
uri = null;
}
if (uri == null)
{
throw new InvalidOperationException(current + " is invalid URI");
}
urls.Add(uri.AbsoluteUri);
}
}
}
private void ProcessLocalPaths(DiscoveryClientProtocol client, StringCollection localPaths, XmlSchemas schemas, ServiceDescriptionCollection descriptions)
{
StringEnumerator enumerator = localPaths.GetEnumerator();
while (enumerator.MoveNext())
{
string current = enumerator.Current;
string extension = Path.GetExtension(current);
if (string.Compare(extension, ".discomap", true) == 0)
{
client.ReadAll(current);
}
else
{
object document = null;
if (string.Compare(extension, ".wsdl", true) == 0)
{
document = this.ReadLocalDocument(false, current);
}
else
{
if (string.Compare(extension, ".xsd", true) != 0)
{
throw new InvalidOperationException("Unknown file type " + current);
}
document = this.ReadLocalDocument(true, current);
}
if (document != null)
{
this.AddDocument(current, document, schemas, descriptions);
}
}
}
}
private void ProcessRemoteUrls(DiscoveryClientProtocol client, StringCollection urls, XmlSchemas schemas, ServiceDescriptionCollection descriptions)
{
StringEnumerator enumerator = urls.GetEnumerator();
while (enumerator.MoveNext())
{
string current = enumerator.Current;
try
{
DiscoveryDocument document = client.DiscoverAny(current);
client.ResolveAll();
continue;
}
catch (Exception exception)
{
throw new InvalidOperationException("General Error " + current, exception);
}
}
IDictionaryEnumerator enumerator2 = client.Documents.GetEnumerator();
while (enumerator2.MoveNext())
{
DictionaryEntry entry = (DictionaryEntry)enumerator2.Current;
this.AddDocument((string)entry.Key, entry.Value, schemas, descriptions);
}
}
private object ReadLocalDocument(bool isSchema, string path)
{
object obj2 = null;
StreamReader input = null;
try
{
input = new StreamReader(path);
if (isSchema)
{
return XmlSchema.Read(new XmlTextReader(input), null);
}
obj2 = ServiceDescription.Read(input.BaseStream);
}
catch
{
throw;
}
finally
{
if (input != null)
{
input.Close();
}
}
return obj2;
}
public static XmlSchema ReadSchema(string filename)
{
XmlTextReader reader = new XmlTextReader(filename);
if (reader.IsStartElement("schema", "http://www.w3.org/2001/XMLSchema"))
{
return XmlSchema.Read(reader, null);
}
return null;
}
public void Reset()
{
this.paths.Clear();
this.compiler = null;
this.wsdls.Clear();
this.xsds.Clear();
this.compileUnit = null;
this.proxyAssembly = null;
this.proxyCode = null;
this.cancelled = false;
}
private void ValidationCallbackWithErrorCode(object sender, ValidationEventArgs args)
{
this.CheckPoint(MessageType.Warning, "Schema parsing error " + args.Message);
}
public StringCollection Paths
{
get
{
return this.paths;
}
}
public Assembly ProxyAssembly
{
get
{
return this.proxyAssembly;
}
}
public string ProxyCode
{
get
{
return this.proxyCode;
}
}
public CodeCompileUnit ProxyCodeDom
{
get
{
return this.compileUnit;
}
}
public string ProxyFileExtension
{
get
{
return this.WsdlProperties.Language.ToString();
}
}
public string ProxyNamespace
{
get
{
return this.proxyNamespace;
}
set
{
this.proxyNamespace = value;
}
}
public WsdlProperties WsdlProperties
{
get
{
return Configuration.MasterConfig.WsdlSettings;
}
}
public StringCollection Wsdls
{
get
{
return this.wsdls;
}
}
public StringCollection Xsds
{
get
{
return this.xsds;
}
}
internal class Namespace
{
public const string SoapEncoding = "http://schemas.xmlsoap.org/soap/encoding/";
public const string Wsdl = "http://schemas.xmlsoap.org/wsdl/";
}
}
}