Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.ServiceModel / System / ServiceModel / Description / SoapHelper.cs
1 //----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------------------
4 namespace System.ServiceModel.Description
5 {
6     using System.Collections.Generic;
7     using System.Runtime;
8     using System.ServiceModel.Dispatcher;
9     using System.Xml;
10     using WsdlNS = System.Web.Services.Description;
11
12     static class SoapHelper
13     {
14         static object SoapVersionStateKey = new object();
15         static XmlDocument xmlDocument;
16
17         static XmlDocument Document
18         {
19             get
20             {
21                 if (xmlDocument == null)
22                     xmlDocument = new XmlDocument();
23                 return xmlDocument;
24             }
25         }
26
27         static XmlAttribute CreateLocalAttribute(string name, string value)
28         {
29             XmlAttribute attribute = Document.CreateAttribute(name);
30             attribute.Value = value;
31             return attribute;
32         }
33         // -----------------------------------------------------------------------------------------------------------------------
34         // Developers Note: We go through a little song an dance here to Get or Create an exsisting SoapBinding from the WSDL
35         // Extensions for a number of reasons:
36         //      1. Multiple Extensions may contribute to the settings in the soap binding and so to make this work without
37         //          relying on ordering, we need the GetOrCreate method.
38         //      2. There are diffrent classes for diffrent SOAP versions and the extensions that determines the version is
39         //          also un-ordered so when we finally figure out the version we may need to recreate the BindingExtension and
40         //          clone it.
41
42         internal static WsdlNS.SoapAddressBinding GetOrCreateSoapAddressBinding(WsdlNS.Binding wsdlBinding, WsdlNS.Port wsdlPort, WsdlExporter exporter)
43         {
44             if (GetSoapVersionState(wsdlBinding, exporter) == EnvelopeVersion.None)
45                 return null;
46
47             WsdlNS.SoapAddressBinding existingSoapAddressBinding = GetSoapAddressBinding(wsdlPort);
48             EnvelopeVersion version = GetSoapVersion(wsdlBinding);
49
50             if (existingSoapAddressBinding != null)
51                 return existingSoapAddressBinding;
52
53             WsdlNS.SoapAddressBinding soapAddressBinding = CreateSoapAddressBinding(version, wsdlPort);
54             return soapAddressBinding;
55         }
56
57         internal static WsdlNS.SoapBinding GetOrCreateSoapBinding(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter)
58         {
59             if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
60                 return null;
61
62             WsdlNS.SoapBinding existingSoapBinding = GetSoapBinding(endpointContext);
63             if (existingSoapBinding != null)
64             {
65                 return existingSoapBinding;
66             }
67
68             EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
69             WsdlNS.SoapBinding soapBinding = CreateSoapBinding(version, endpointContext.WsdlBinding);
70             return soapBinding;
71         }
72
73         internal static WsdlNS.SoapOperationBinding GetOrCreateSoapOperationBinding(WsdlEndpointConversionContext endpointContext, OperationDescription operation, WsdlExporter exporter)
74         {
75             if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
76                 return null;
77
78             WsdlNS.SoapOperationBinding existingSoapOperationBinding = GetSoapOperationBinding(endpointContext, operation);
79             WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation);
80             EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
81
82             if (existingSoapOperationBinding != null)
83                 return existingSoapOperationBinding;
84
85             WsdlNS.SoapOperationBinding soapOperationBinding = CreateSoapOperationBinding(version, wsdlOperationBinding);
86             return soapOperationBinding;
87         }
88
89         internal static WsdlNS.SoapBodyBinding GetOrCreateSoapBodyBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.MessageBinding wsdlMessageBinding, WsdlExporter exporter)
90         {
91             if (GetSoapVersionState(endpointContext.WsdlBinding, exporter) == EnvelopeVersion.None)
92                 return null;
93
94             WsdlNS.SoapBodyBinding existingSoapBodyBinding = GetSoapBodyBinding(endpointContext, wsdlMessageBinding);
95             EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
96
97             if (existingSoapBodyBinding != null)
98                 return existingSoapBodyBinding;
99
100             WsdlNS.SoapBodyBinding soapBodyBinding = CreateSoapBodyBinding(version, wsdlMessageBinding);
101             return soapBodyBinding;
102         }
103
104         internal static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.MessageBinding wsdlMessageBinding)
105         {
106             EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
107
108             WsdlNS.SoapHeaderBinding soapHeaderBinding = CreateSoapHeaderBinding(version, wsdlMessageBinding);
109             return soapHeaderBinding;
110         }
111
112         internal static void CreateSoapFaultBinding(string name, WsdlEndpointConversionContext endpointContext, WsdlNS.FaultBinding wsdlFaultBinding, bool isEncoded)
113         {
114             EnvelopeVersion version = GetSoapVersion(endpointContext.WsdlBinding);
115             XmlElement fault = CreateSoapFaultBinding(version);
116             fault.Attributes.Append(CreateLocalAttribute("name", name));
117             fault.Attributes.Append(CreateLocalAttribute("use", isEncoded ? "encoded" : "literal"));
118             wsdlFaultBinding.Extensions.Add(fault);
119         }
120
121         internal static void SetSoapVersion(WsdlEndpointConversionContext endpointContext, WsdlExporter exporter, EnvelopeVersion version)
122         {
123             SetSoapVersionState(endpointContext.WsdlBinding, exporter, version);
124
125             //Convert all SOAP extensions to the right version.
126             if (endpointContext.WsdlPort != null)
127                 SoapConverter.ConvertExtensions(endpointContext.WsdlPort.Extensions, version, SoapConverter.ConvertSoapAddressBinding);
128
129             SoapConverter.ConvertExtensions(endpointContext.WsdlBinding.Extensions, version, SoapConverter.ConvertSoapBinding);
130
131             foreach (WsdlNS.OperationBinding operationBinding in endpointContext.WsdlBinding.Operations)
132             {
133                 SoapConverter.ConvertExtensions(operationBinding.Extensions, version, SoapConverter.ConvertSoapOperationBinding);
134
135                 //Messages
136                 {
137                     if (operationBinding.Input != null)
138                         SoapConverter.ConvertExtensions(operationBinding.Input.Extensions, version, SoapConverter.ConvertSoapMessageBinding);
139                     if (operationBinding.Output != null)
140                         SoapConverter.ConvertExtensions(operationBinding.Output.Extensions, version, SoapConverter.ConvertSoapMessageBinding);
141
142                     foreach (WsdlNS.MessageBinding faultBinding in operationBinding.Faults)
143                         SoapConverter.ConvertExtensions(faultBinding.Extensions, version, SoapConverter.ConvertSoapMessageBinding);
144                 }
145             }
146
147         }
148
149         internal static EnvelopeVersion GetSoapVersion(WsdlNS.Binding wsdlBinding)
150         {
151             foreach (object o in wsdlBinding.Extensions)
152             {
153                 if (o is WsdlNS.SoapBinding)
154                     return o is WsdlNS.Soap12Binding ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11;
155             }
156             return EnvelopeVersion.Soap12;
157         }
158
159         private static void SetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter, EnvelopeVersion version)
160         {
161             object versions = null;
162
163             if (!exporter.State.TryGetValue(SoapVersionStateKey, out versions))
164             {
165                 versions = new Dictionary<WsdlNS.Binding, EnvelopeVersion>();
166                 exporter.State[SoapVersionStateKey] = versions;
167             }
168
169             ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding] = version;
170         }
171
172         private static EnvelopeVersion GetSoapVersionState(WsdlNS.Binding wsdlBinding, WsdlExporter exporter)
173         {
174             object versions = null;
175
176             if (exporter.State.TryGetValue(SoapVersionStateKey, out versions))
177             {
178                 if (versions != null && ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions).ContainsKey(wsdlBinding))
179                 {
180                     return ((Dictionary<WsdlNS.Binding, EnvelopeVersion>)versions)[wsdlBinding];
181                 }
182             }
183             return null;
184         }
185
186         static class SoapConverter
187         {
188
189             // Microsoft, this could be simplified if we used generics.
190             internal static void ConvertExtensions(WsdlNS.ServiceDescriptionFormatExtensionCollection extensions, EnvelopeVersion version, ConvertExtension conversionMethod)
191             {
192                 bool foundOne = false;
193                 for (int i = extensions.Count - 1; i >= 0; i--)
194                 {
195                     object o = extensions[i];
196                     if (conversionMethod(ref o, version))
197                     {
198                         if (o == null)
199                             extensions.Remove(extensions[i]);
200                         else
201                             extensions[i] = o;
202                         foundOne = true;
203                     }
204                 }
205
206                 if (!foundOne)
207                 {
208                     object o = null;
209                     conversionMethod(ref o, version);
210                     if (o != null)
211                         extensions.Add(o);
212                 }
213
214             }
215
216             // This is the delegate implemented by the 4 methods below. It is expected to:
217             // If given a null reference for src, a new instance of the extension can be set.
218             internal delegate bool ConvertExtension(ref object src, EnvelopeVersion version);
219
220             internal static bool ConvertSoapBinding(ref object src, EnvelopeVersion version)
221             {
222                 WsdlNS.SoapBinding binding = src as WsdlNS.SoapBinding;
223
224                 if (src != null)
225                 {
226                     if (binding == null)
227                         return false; // not a soap object
228                     else if (GetBindingVersion<WsdlNS.Soap12Binding>(src) == version)
229                         return true; // matched but same version; no change
230                 }
231
232                 if (version == EnvelopeVersion.None)
233                 {
234                     src = null;
235                     return true;
236                 }
237
238                 WsdlNS.SoapBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12Binding() : new WsdlNS.SoapBinding();
239                 if (binding != null)
240                 {
241                     dest.Required = binding.Required;
242                     dest.Style = binding.Style;
243                     dest.Transport = binding.Transport;
244                 }
245
246                 src = dest;
247                 return true;
248             }
249
250             internal static bool ConvertSoapAddressBinding(ref object src, EnvelopeVersion version)
251             {
252                 WsdlNS.SoapAddressBinding binding = src as WsdlNS.SoapAddressBinding;
253
254                 if (src != null)
255                 {
256                     if (binding == null)
257                         return false; // no match
258                     else if (GetBindingVersion<WsdlNS.Soap12AddressBinding>(src) == version)
259                         return true; // matched but same version; no change
260                 }
261
262                 if (version == EnvelopeVersion.None)
263                 {
264                     src = null;
265                     return true;
266                 }
267
268                 WsdlNS.SoapAddressBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12AddressBinding() : new WsdlNS.SoapAddressBinding();
269                 if (binding != null)
270                 {
271                     dest.Required = binding.Required;
272                     dest.Location = binding.Location;
273                 }
274
275                 src = dest;
276                 return true;
277             }
278
279
280             // returns true if src is an expected type; updates src in place; should handle null
281             internal static bool ConvertSoapOperationBinding(ref object src, EnvelopeVersion version)
282             {
283                 WsdlNS.SoapOperationBinding binding = src as WsdlNS.SoapOperationBinding;
284
285                 if (src != null)
286                 {
287                     if (binding == null)
288                         return false; // no match
289                     else if (GetBindingVersion<WsdlNS.Soap12OperationBinding>(src) == version)
290                         return true; // matched but same version
291                 }
292
293                 if (version == EnvelopeVersion.None)
294                 {
295                     src = null;
296                     return true;
297                 }
298
299                 WsdlNS.SoapOperationBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12OperationBinding() : new WsdlNS.SoapOperationBinding();
300                 if (src != null)
301                 {
302                     dest.Required = binding.Required;
303                     dest.Style = binding.Style;
304                     dest.SoapAction = binding.SoapAction;
305                 }
306
307                 src = dest;
308                 return true;
309             }
310
311             internal static bool ConvertSoapMessageBinding(ref object src, EnvelopeVersion version)
312             {
313                 WsdlNS.SoapBodyBinding body = src as WsdlNS.SoapBodyBinding;
314                 if (body != null)
315                 {
316                     src = ConvertSoapBodyBinding(body, version);
317                     return true;
318                 }
319
320                 WsdlNS.SoapHeaderBinding header = src as WsdlNS.SoapHeaderBinding;
321                 if (header != null)
322                 {
323                     src = ConvertSoapHeaderBinding(header, version);
324                     return true;
325                 }
326
327                 WsdlNS.SoapFaultBinding fault = src as WsdlNS.SoapFaultBinding;
328                 if (fault != null)
329                 {
330                     src = ConvertSoapFaultBinding(fault, version);
331                     return true;
332                 }
333
334                 XmlElement element = src as XmlElement;
335                 if (element != null)
336                 {
337                     if (IsSoapFaultBinding(element))
338                     {
339                         src = ConvertSoapFaultBinding(element, version);
340                         return true;
341                     }
342                 }
343
344                 return src == null; // "match" only if nothing passed in
345             }
346
347             static WsdlNS.SoapBodyBinding ConvertSoapBodyBinding(WsdlNS.SoapBodyBinding src, EnvelopeVersion version)
348             {
349                 if (version == EnvelopeVersion.None)
350                     return null;
351
352                 EnvelopeVersion srcVersion = GetBindingVersion<WsdlNS.Soap12BodyBinding>(src);
353                 if (srcVersion == version)
354                     return src;
355
356                 WsdlNS.SoapBodyBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12BodyBinding() : new WsdlNS.SoapBodyBinding();
357                 if (src != null)
358                 {
359                     if (XmlSerializerOperationFormatter.GetEncoding(srcVersion) == src.Encoding)
360                         dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version);
361                     dest.Encoding = XmlSerializerOperationFormatter.GetEncoding(version);
362                     dest.Namespace = src.Namespace;
363                     dest.Parts = src.Parts;
364                     dest.PartsString = src.PartsString;
365                     dest.Use = src.Use;
366                     dest.Required = src.Required;
367                 }
368                 return dest;
369             }
370
371             static XmlElement ConvertSoapFaultBinding(XmlElement src, EnvelopeVersion version)
372             {
373                 if (src == null)
374                     return null;
375
376                 if (version == EnvelopeVersion.Soap12)
377                 {
378                     if (src.NamespaceURI == WsdlNS.Soap12Binding.Namespace)
379                         return src;
380                 }
381                 else if (version == EnvelopeVersion.Soap11)
382                 {
383                     if (src.NamespaceURI == WsdlNS.SoapBinding.Namespace)
384                         return src;
385                 }
386                 else
387                 {
388                     return null;
389                 }
390
391                 XmlElement dest = CreateSoapFaultBinding(version);
392                 if (src.HasAttributes)
393                 {
394                     foreach (XmlAttribute attribute in src.Attributes)
395                     {
396                         dest.SetAttribute(attribute.Name, attribute.Value);
397                     }
398                 }
399                 return dest;
400             }
401
402             static WsdlNS.SoapFaultBinding ConvertSoapFaultBinding(WsdlNS.SoapFaultBinding src, EnvelopeVersion version)
403             {
404                 if (version == EnvelopeVersion.None)
405                     return null;
406
407                 if (GetBindingVersion<WsdlNS.Soap12FaultBinding>(src) == version)
408                     return src;
409
410                 WsdlNS.SoapFaultBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12FaultBinding() : new WsdlNS.SoapFaultBinding();
411                 if (src != null)
412                 {
413                     dest.Encoding = src.Encoding;
414                     dest.Name = src.Name;
415                     dest.Namespace = src.Namespace;
416                     dest.Use = src.Use;
417                     dest.Required = src.Required;
418                 }
419                 return dest;
420             }
421
422             static WsdlNS.SoapHeaderBinding ConvertSoapHeaderBinding(WsdlNS.SoapHeaderBinding src, EnvelopeVersion version)
423             {
424                 if (version == EnvelopeVersion.None)
425                     return null;
426
427                 if (GetBindingVersion<WsdlNS.Soap12HeaderBinding>(src) == version)
428                     return src;
429
430                 WsdlNS.SoapHeaderBinding dest = version == EnvelopeVersion.Soap12 ? new WsdlNS.Soap12HeaderBinding() : new WsdlNS.SoapHeaderBinding();
431                 if (src != null)
432                 {
433                     dest.Fault = src.Fault;
434                     dest.MapToProperty = src.MapToProperty;
435                     dest.Message = src.Message;
436                     dest.Part = src.Part;
437                     dest.Encoding = src.Encoding;
438                     dest.Namespace = src.Namespace;
439                     dest.Use = src.Use;
440                     dest.Required = src.Required;
441                 }
442                 return dest;
443             }
444
445             internal static EnvelopeVersion GetBindingVersion<T12>(object src)
446             {
447                 return src is T12 ? EnvelopeVersion.Soap12 : EnvelopeVersion.Soap11;
448             }
449
450         }
451
452         static WsdlNS.SoapAddressBinding CreateSoapAddressBinding(EnvelopeVersion version, WsdlNS.Port wsdlPort)
453         {
454             WsdlNS.SoapAddressBinding soapAddressBinding = null;
455
456             if (version == EnvelopeVersion.Soap12)
457             {
458                 soapAddressBinding = new WsdlNS.Soap12AddressBinding();
459             }
460             else if (version == EnvelopeVersion.Soap11)
461             {
462                 soapAddressBinding = new WsdlNS.SoapAddressBinding();
463             }
464             Fx.Assert(soapAddressBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
465
466             wsdlPort.Extensions.Add(soapAddressBinding);
467             return soapAddressBinding;
468         }
469
470         // 
471         static WsdlNS.SoapBinding CreateSoapBinding(EnvelopeVersion version, WsdlNS.Binding wsdlBinding)
472         {
473             WsdlNS.SoapBinding soapBinding = null;
474
475             if (version == EnvelopeVersion.Soap12)
476             {
477                 soapBinding = new WsdlNS.Soap12Binding();
478             }
479             else if (version == EnvelopeVersion.Soap11)
480             {
481                 soapBinding = new WsdlNS.SoapBinding();
482             }
483             Fx.Assert(soapBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
484
485             wsdlBinding.Extensions.Add(soapBinding);
486             return soapBinding;
487         }
488
489         static WsdlNS.SoapOperationBinding CreateSoapOperationBinding(EnvelopeVersion version, WsdlNS.OperationBinding wsdlOperationBinding)
490         {
491             WsdlNS.SoapOperationBinding soapOperationBinding = null;
492
493             if (version == EnvelopeVersion.Soap12)
494             {
495                 soapOperationBinding = new WsdlNS.Soap12OperationBinding();
496             }
497             else if (version == EnvelopeVersion.Soap11)
498             {
499                 soapOperationBinding = new WsdlNS.SoapOperationBinding();
500             }
501             Fx.Assert(soapOperationBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
502
503             wsdlOperationBinding.Extensions.Add(soapOperationBinding);
504             return soapOperationBinding;
505         }
506
507         static WsdlNS.SoapBodyBinding CreateSoapBodyBinding(EnvelopeVersion version, WsdlNS.MessageBinding wsdlMessageBinding)
508         {
509             WsdlNS.SoapBodyBinding soapBodyBinding = null;
510
511             if (version == EnvelopeVersion.Soap12)
512             {
513                 soapBodyBinding = new WsdlNS.Soap12BodyBinding();
514             }
515             else if (version == EnvelopeVersion.Soap11)
516             {
517                 soapBodyBinding = new WsdlNS.SoapBodyBinding();
518             }
519             Fx.Assert(soapBodyBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
520
521             wsdlMessageBinding.Extensions.Add(soapBodyBinding);
522             return soapBodyBinding;
523         }
524
525         static WsdlNS.SoapHeaderBinding CreateSoapHeaderBinding(EnvelopeVersion version, WsdlNS.MessageBinding wsdlMessageBinding)
526         {
527             WsdlNS.SoapHeaderBinding soapHeaderBinding = null;
528
529             if (version == EnvelopeVersion.Soap12)
530             {
531                 soapHeaderBinding = new WsdlNS.Soap12HeaderBinding();
532             }
533             else if (version == EnvelopeVersion.Soap11)
534             {
535                 soapHeaderBinding = new WsdlNS.SoapHeaderBinding();
536             }
537             Fx.Assert(soapHeaderBinding != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
538
539             wsdlMessageBinding.Extensions.Add(soapHeaderBinding);
540             return soapHeaderBinding;
541         }
542
543         static XmlElement CreateSoapFaultBinding(EnvelopeVersion version)
544         {
545             string prefix = null;
546             string ns = null;
547             if (version == EnvelopeVersion.Soap12)
548             {
549                 ns = WsdlNS.Soap12Binding.Namespace;
550                 prefix = "soap12";
551             }
552             else if (version == EnvelopeVersion.Soap11)
553             {
554                 ns = WsdlNS.SoapBinding.Namespace;
555                 prefix = "soap";
556             }
557             Fx.Assert(ns != null, "EnvelopeVersion is not recognized. Please update the SoapHelper class");
558             return Document.CreateElement(prefix, "fault", ns);
559         }
560
561
562         internal static WsdlNS.SoapAddressBinding GetSoapAddressBinding(WsdlNS.Port wsdlPort)
563         {
564             foreach (object o in wsdlPort.Extensions)
565             {
566                 if (o is WsdlNS.SoapAddressBinding)
567                     return (WsdlNS.SoapAddressBinding)o;
568             }
569             return null;
570         }
571         static WsdlNS.SoapBinding GetSoapBinding(WsdlEndpointConversionContext endpointContext)
572         {
573             foreach (object o in endpointContext.WsdlBinding.Extensions)
574             {
575                 if (o is WsdlNS.SoapBinding)
576                     return (WsdlNS.SoapBinding)o;
577             }
578             return null;
579         }
580
581         static WsdlNS.SoapOperationBinding GetSoapOperationBinding(WsdlEndpointConversionContext endpointContext, OperationDescription operation)
582         {
583             WsdlNS.OperationBinding wsdlOperationBinding = endpointContext.GetOperationBinding(operation);
584
585             foreach (object o in wsdlOperationBinding.Extensions)
586             {
587                 if (o is WsdlNS.SoapOperationBinding)
588                     return (WsdlNS.SoapOperationBinding)o;
589             }
590             return null;
591         }
592
593         static WsdlNS.SoapBodyBinding GetSoapBodyBinding(WsdlEndpointConversionContext endpointContext, WsdlNS.MessageBinding wsdlMessageBinding)
594         {
595             foreach (object o in wsdlMessageBinding.Extensions)
596             {
597                 if (o is WsdlNS.SoapBodyBinding)
598                     return (WsdlNS.SoapBodyBinding)o;
599             }
600             return null;
601         }
602
603         internal static string ReadSoapAction(WsdlNS.OperationBinding wsdlOperationBinding)
604         {
605             WsdlNS.SoapOperationBinding soapOperationBinding = (WsdlNS.SoapOperationBinding)wsdlOperationBinding.Extensions.Find(typeof(WsdlNS.SoapOperationBinding));
606             return soapOperationBinding != null ? soapOperationBinding.SoapAction : null;
607         }
608
609         internal static WsdlNS.SoapBindingStyle GetStyle(WsdlNS.Binding binding)
610         {
611             WsdlNS.SoapBindingStyle style = WsdlNS.SoapBindingStyle.Default;
612             if (binding != null)
613             {
614                 WsdlNS.SoapBinding soapBinding = binding.Extensions.Find(typeof(WsdlNS.SoapBinding)) as WsdlNS.SoapBinding;
615                 if (soapBinding != null)
616                     style = soapBinding.Style;
617             }
618             return style;
619         }
620
621         internal static WsdlNS.SoapBindingStyle GetStyle(WsdlNS.OperationBinding operationBinding, WsdlNS.SoapBindingStyle defaultBindingStyle)
622         {
623             WsdlNS.SoapBindingStyle style = defaultBindingStyle;
624             if (operationBinding != null)
625             {
626                 WsdlNS.SoapOperationBinding soapOperationBinding = operationBinding.Extensions.Find(typeof(WsdlNS.SoapOperationBinding)) as WsdlNS.SoapOperationBinding;
627                 if (soapOperationBinding != null)
628                 {
629                     if (soapOperationBinding.Style != WsdlNS.SoapBindingStyle.Default)
630                         style = soapOperationBinding.Style;
631                 }
632             }
633             return style;
634         }
635
636         internal static bool IsSoapFaultBinding(XmlElement element)
637         {
638             return (element != null && element.LocalName == "fault" && (element.NamespaceURI == WsdlNS.Soap12Binding.Namespace || element.NamespaceURI == WsdlNS.SoapBinding.Namespace));
639         }
640
641         internal static bool IsEncoded(XmlElement element)
642         {
643             Fx.Assert(element != null, "");
644             XmlAttribute attribute = element.GetAttributeNode("use");
645             if (attribute == null)
646                 return false;
647             return attribute.Value == "encoded";
648         }
649     }
650 }