2 // System.Web.Services.Description.SoapProtocolImporter.cs
5 // Tim Coleman (tim@timcoleman.com)
6 // Lluis Sanchez Gual (lluis@ximian.com)
8 // Copyright (C) Tim Coleman, 2002
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Web.Services;
34 using System.Web.Services.Protocols;
35 using System.Web.Services.Configuration;
37 using System.Xml.Schema;
38 using System.Xml.Serialization;
39 using System.Configuration;
40 using System.Collections;
42 namespace System.Web.Services.Description {
43 public class SoapProtocolImporter : ProtocolImporter {
47 SoapBinding soapBinding;
48 SoapCodeExporter soapExporter;
49 SoapSchemaImporter soapImporter;
50 XmlCodeExporter xmlExporter;
51 XmlSchemaImporter xmlImporter;
52 CodeIdentifiers memberIds;
53 ArrayList extensionImporters;
54 Hashtable headerVariables;
55 XmlSchemas xmlSchemas;
56 XmlSchemas soapSchemas;
62 public SoapProtocolImporter ()
64 extensionImporters = ExtensionManager.BuildExtensionImporters ();
67 void SetBinding (SoapBinding soapBinding)
69 this.soapBinding = soapBinding;
72 #endregion // Constructors
76 public override string ProtocolName {
77 get { return "Soap"; }
80 public SoapBinding SoapBinding {
81 get { return soapBinding; }
84 public SoapCodeExporter SoapExporter {
85 get { return soapExporter; }
88 public SoapSchemaImporter SoapImporter {
89 get { return soapImporter; }
92 public XmlCodeExporter XmlExporter {
93 get { return xmlExporter; }
96 public XmlSchemaImporter XmlImporter {
97 get { return xmlImporter; }
100 #endregion // Properties
104 protected override CodeTypeDeclaration BeginClass ()
106 soapBinding = (SoapBinding) Binding.Extensions.Find (typeof(SoapBinding));
108 CodeTypeDeclaration codeClass = new CodeTypeDeclaration (ClassName);
110 string location = null;
113 SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
114 if (sab != null) location = sab.Location;
117 string namspace = (Port != null ? Port.Binding.Namespace : Binding.ServiceDescription.TargetNamespace);
118 string name = (Port != null ? Port.Name : Binding.Name);
120 if (Style == ServiceDescriptionImportStyle.Client) {
121 CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.SoapHttpClientProtocol");
122 codeClass.BaseTypes.Add (ctr);
125 CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.WebService");
126 codeClass.BaseTypes.Add (ctr);
127 CodeAttributeDeclaration attws = new CodeAttributeDeclaration ("System.Web.Services.WebServiceAttribute");
128 attws.Arguments.Add (GetArg ("Namespace", namspace));
129 AddCustomAttribute (codeClass, attws, true);
132 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
133 att.Arguments.Add (GetArg ("Name", name));
134 att.Arguments.Add (GetArg ("Namespace", namspace));
135 AddCustomAttribute (codeClass, att, true);
137 if (Style == ServiceDescriptionImportStyle.Client) {
138 CodeConstructor cc = new CodeConstructor ();
139 cc.Attributes = MemberAttributes.Public;
140 GenerateServiceUrl (location, cc.Statements);
143 if (ProtocolName.ToUpper () == "SOAP12") {
144 CodeExpression thisSoapVer = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), "SoapVersion");
145 CodeFieldReferenceExpression soap12Enum =
146 new CodeFieldReferenceExpression (new CodeTypeReferenceExpression (typeof (SoapProtocolVersion)), "Soap12");
147 cc.Statements.Add (new CodeAssignStatement (thisSoapVer, soap12Enum));
150 codeClass.Members.Add (cc);
153 memberIds = new CodeIdentifiers ();
154 headerVariables = new Hashtable ();
158 protected override void BeginNamespace ()
161 xmlImporter = new XmlSchemaImporter (LiteralSchemas, base.CodeGenerationOptions, base.CodeGenerator, base.ImportContext);
162 soapImporter = new SoapSchemaImporter (EncodedSchemas, base.CodeGenerationOptions, base.CodeGenerator, base.ImportContext);
163 xmlExporter = new XmlCodeExporter (CodeNamespace, null, base.CodeGenerator, base.CodeGenerationOptions, null);
164 soapExporter = new SoapCodeExporter (CodeNamespace, null, base.CodeGenerator, base.CodeGenerationOptions, null);
166 xmlImporter = new XmlSchemaImporter (LiteralSchemas, ClassNames);
167 soapImporter = new SoapSchemaImporter (EncodedSchemas, ClassNames);
168 xmlExporter = new XmlCodeExporter (CodeNamespace, null);
169 soapExporter = new SoapCodeExporter (CodeNamespace, null);
173 protected override void EndClass ()
175 SoapTransportImporter transportImporter = SoapTransportImporter.FindTransportImporter (soapBinding.Transport);
176 if (transportImporter == null) throw new InvalidOperationException ("Transport '" + soapBinding.Transport + "' not supported");
177 transportImporter.ImportContext = this;
178 transportImporter.ImportClass ();
180 if (xmlExporter.IncludeMetadata.Count > 0 || soapExporter.IncludeMetadata.Count > 0)
182 if (CodeTypeDeclaration.CustomAttributes == null)
183 CodeTypeDeclaration.CustomAttributes = new CodeAttributeDeclarationCollection ();
184 CodeTypeDeclaration.CustomAttributes.AddRange (xmlExporter.IncludeMetadata);
185 CodeTypeDeclaration.CustomAttributes.AddRange (soapExporter.IncludeMetadata);
189 protected override void EndNamespace ()
193 protected override bool IsBindingSupported ()
196 object o = Binding.Extensions.Find (typeof(SoapBinding));
197 return o != null && !(o is Soap12Binding);
199 return Binding.Extensions.Find (typeof(SoapBinding)) != null;
204 protected override bool IsOperationFlowSupported (OperationFlow flow)
206 throw new NotImplementedException ();
209 static readonly char [] whitespaces = new char [] {' ', '\t', '\n', '\r'};
211 protected virtual bool IsSoapEncodingPresent (string uriList)
213 foreach (string s in uriList.Split (whitespaces))
214 if (s == "http://schemas.xmlsoap.org/soap/encoding/")
219 protected override CodeMemberMethod GenerateMethod ()
223 SoapOperationBinding soapOper = OperationBinding.Extensions.Find (typeof (SoapOperationBinding)) as SoapOperationBinding;
224 if (soapOper == null) throw new InvalidOperationException ("Soap operation binding not found");
226 SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style;
228 SoapBodyBinding isbb = null;
229 XmlMembersMapping inputMembers = null;
231 bool isWrapped = CheckIsWrapped ();
233 isbb = OperationBinding.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
234 if (isbb == null) throw new InvalidOperationException ("Soap body binding not found");
236 inputMembers = ImportMembersMapping (InputMessage, isbb, style, false, isWrapped);
237 if (inputMembers == null) throw new InvalidOperationException ("Input message not declared");
239 // If OperationBinding.Output is null, it is an OneWay operation
241 SoapBodyBinding osbb = null;
242 XmlMembersMapping outputMembers = null;
244 if (OperationBinding.Output != null) {
245 osbb = OperationBinding.Output.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
246 if (osbb == null) throw new InvalidOperationException ("Soap body binding not found");
248 outputMembers = ImportMembersMapping (OutputMessage, osbb, style, true, isWrapped);
249 if (outputMembers == null) throw new InvalidOperationException ("Output message not declared");
252 CodeMemberMethod met = GenerateMethod (memberIds, soapOper, isbb, inputMembers, outputMembers);
254 if (isbb.Use == SoapBindingUse.Literal)
255 xmlExporter.ExportMembersMapping (inputMembers);
257 soapExporter.ExportMembersMapping (inputMembers);
260 if (osbb.Use == SoapBindingUse.Literal)
261 xmlExporter.ExportMembersMapping (outputMembers);
263 soapExporter.ExportMembersMapping (outputMembers);
266 foreach (SoapExtensionImporter eximporter in extensionImporters)
268 eximporter.ImportContext = this;
269 eximporter.ImportMethod (met.CustomAttributes);
274 catch (InvalidOperationException ex)
276 UnsupportedOperationBindingWarning (ex.Message);
281 bool CheckIsWrapped ()
283 return (OutputMessage == null || (OutputMessage.Parts.Count == 1 && OutputMessage.Parts[0].Name == "parameters")) &&
284 (InputMessage == null || (InputMessage.Parts.Count == 1 && InputMessage.Parts[0].Name == "parameters"));
287 XmlMembersMapping ImportMembersMapping (Message msg, SoapBodyBinding sbb, SoapBindingStyle style, bool output, bool wrapped)
289 string elemName = Operation.Name;
290 if (output) elemName += "Response";
294 // Wrapped parameter style
296 MessagePart part = msg.Parts[0];
297 if (sbb.Use == SoapBindingUse.Encoded)
299 SoapSchemaMember ssm = new SoapSchemaMember ();
300 ssm.MemberName = part.Name;
301 ssm.MemberType = part.Type;
302 return soapImporter.ImportMembersMapping (elemName, part.Type.Namespace, ssm);
305 return xmlImporter.ImportMembersMapping (part.Element);
309 if (sbb.Use == SoapBindingUse.Encoded)
311 SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count];
312 for (int n=0; n<mems.Length; n++)
314 SoapSchemaMember mem = new SoapSchemaMember();
315 mem.MemberName = msg.Parts[n].Name;
316 mem.MemberType = msg.Parts[n].Type;
320 // Rpc messages always have a wrapping element
321 if (style == SoapBindingStyle.Rpc)
322 return soapImporter.ImportMembersMapping (elemName, sbb.Namespace, mems, true);
324 return soapImporter.ImportMembersMapping ("", "", mems, false);
328 if (style == SoapBindingStyle.Rpc)
329 throw new InvalidOperationException ("The combination of style=rpc with use=literal is not supported");
331 if (msg.Parts.Count == 1 && msg.Parts[0].Type != XmlQualifiedName.Empty)
332 return xmlImporter.ImportAnyType (msg.Parts[0].Type, null);
335 XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count];
336 for (int n=0; n<pnames.Length; n++)
337 pnames[n] = msg.Parts[n].Element;
338 return xmlImporter.ImportMembersMapping (pnames);
344 CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, SoapOperationBinding soapOper, SoapBodyBinding bodyBinding, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers)
346 CodeIdentifiers pids = new CodeIdentifiers ();
347 CodeMemberMethod method = new CodeMemberMethod ();
348 CodeMemberMethod methodBegin = new CodeMemberMethod ();
349 CodeMemberMethod methodEnd = new CodeMemberMethod ();
350 method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
351 methodBegin.Attributes = MemberAttributes.Public | MemberAttributes.Final;
352 methodEnd.Attributes = MemberAttributes.Public | MemberAttributes.Final;
354 SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style;
356 // Find unique names for temporary variables
358 for (int n=0; n<inputMembers.Count; n++)
359 pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);
361 if (outputMembers != null)
362 for (int n=0; n<outputMembers.Count; n++)
363 pids.AddUnique (outputMembers[n].MemberName, outputMembers[n]);
365 string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
366 string varResults = pids.AddUnique ("results","results");
367 string varCallback = pids.AddUnique ("callback","callback");
368 string varAsyncState = pids.AddUnique ("asyncState","asyncState");
370 string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);
372 method.Name = CodeIdentifier.MakeValid(Operation.Name);
373 if (method.Name == ClassName) method.Name += "1";
374 methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + method.Name),method);
375 methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + method.Name),method);
377 method.ReturnType = new CodeTypeReference (typeof(void));
378 methodEnd.ReturnType = new CodeTypeReference (typeof(void));
379 methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));
381 CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];
382 CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers != null ? outputMembers.Count : 0];
384 for (int n=0; n<inputMembers.Count; n++)
386 CodeParameterDeclarationExpression param = GenerateParameter (inputMembers[n], FieldDirection.In);
387 method.Parameters.Add (param);
388 GenerateMemberAttributes (inputMembers, inputMembers[n], bodyBinding.Use, param);
389 methodBegin.Parameters.Add (GenerateParameter (inputMembers[n], FieldDirection.In));
390 paramArray [n] = new CodeVariableReferenceExpression (param.Name);
393 if (outputMembers != null)
395 bool hasReturn = false;
396 for (int n=0; n<outputMembers.Count; n++)
398 CodeParameterDeclarationExpression cpd = GenerateParameter (outputMembers[n], FieldDirection.Out);
402 foreach (CodeParameterDeclarationExpression ip in method.Parameters)
404 if (ip.Name == cpd.Name && ip.Type.BaseType == cpd.Type.BaseType) {
405 ip.Direction = FieldDirection.Ref;
406 methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
417 method.ReturnType = cpd.Type;
418 methodEnd.ReturnType = cpd.Type;
419 GenerateReturnAttributes (outputMembers, outputMembers[n], bodyBinding.Use, method);
420 outParams [n] = null;
424 method.Parameters.Add (cpd);
425 GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd);
426 methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
430 methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
431 methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
432 methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));
434 // Array of input parameters
436 CodeArrayCreateExpression methodParams;
437 if (paramArray.Length > 0)
438 methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
440 methodParams = new CodeArrayCreateExpression (typeof(object), 0);
442 // Assignment of output parameters
444 CodeStatementCollection outAssign = new CodeStatementCollection ();
445 CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults);
446 for (int n=0; n<outParams.Length; n++)
448 CodeExpression index = new CodePrimitiveExpression (n);
449 if (outParams[n] == null)
451 CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index));
452 outAssign.Add (new CodeMethodReturnStatement (res));
456 CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index));
457 CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name);
458 outAssign.Insert (0, new CodeAssignStatement (var, res));
462 if (Style == ServiceDescriptionImportStyle.Client)
466 CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
467 CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
468 CodeMethodInvokeExpression inv;
469 CodeVariableDeclarationStatement dec;
471 inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams);
472 if (outputMembers != null && outputMembers.Count > 0)
474 dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
475 method.Statements.Add (dec);
476 method.Statements.AddRange (outAssign);
479 method.Statements.Add (inv);
483 CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
484 CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
485 inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs);
486 methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
490 CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
491 inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
492 if (outputMembers != null && outputMembers.Count > 0)
494 dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
495 methodEnd.Statements.Add (dec);
496 methodEnd.Statements.AddRange (outAssign);
499 methodEnd.Statements.Add (inv);
502 method.Attributes = MemberAttributes.Public | MemberAttributes.Abstract;
507 ImportHeaders (method);
509 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebMethodAttribute");
510 if (messageName != method.Name) att.Arguments.Add (GetArg ("MessageName",messageName));
511 AddCustomAttribute (method, att, (Style == ServiceDescriptionImportStyle.Server));
513 if (style == SoapBindingStyle.Rpc)
515 att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapRpcMethodAttribute");
516 att.Arguments.Add (GetArg (soapOper.SoapAction));
517 if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
518 if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
519 att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
520 if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
521 if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
525 if (outputMembers != null && (inputMembers.ElementName == "" && outputMembers.ElementName != "" ||
526 inputMembers.ElementName != "" && outputMembers.ElementName == ""))
527 throw new InvalidOperationException ("Parameter style is not the same for the input message and output message");
529 att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapDocumentMethodAttribute");
530 att.Arguments.Add (GetArg (soapOper.SoapAction));
531 if (inputMembers.ElementName != "") {
532 if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
533 if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
534 att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
535 if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
536 att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Wrapped"));
539 att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Bare"));
541 if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
543 att.Arguments.Add (GetEnumArg ("Use", "System.Web.Services.Description.SoapBindingUse", bodyBinding.Use.ToString()));
546 AddCustomAttribute (method, att, true);
548 CodeTypeDeclaration.Members.Add (method);
550 if (Style == ServiceDescriptionImportStyle.Client) {
551 CodeTypeDeclaration.Members.Add (methodBegin);
552 CodeTypeDeclaration.Members.Add (methodEnd);
558 CodeParameterDeclarationExpression GenerateParameter (XmlMemberMapping member, FieldDirection dir)
561 string type = member.GenerateTypeName (CodeGenerator);
563 string type = member.TypeFullName;
565 CodeParameterDeclarationExpression par = new CodeParameterDeclarationExpression (type, member.MemberName);
570 void GenerateMemberAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeParameterDeclarationExpression param)
572 if (use == SoapBindingUse.Literal)
573 xmlExporter.AddMappingMetadata (param.CustomAttributes, member, members.Namespace);
575 soapExporter.AddMappingMetadata (param.CustomAttributes, member);
578 void GenerateReturnAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeMemberMethod method)
580 if (use == SoapBindingUse.Literal)
581 xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, members.Namespace, (member.ElementName != method.Name + "Result"));
583 soapExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, (member.ElementName != method.Name + "Result"));
586 void ImportHeaders (CodeMemberMethod method)
588 foreach (object ob in OperationBinding.Input.Extensions)
590 SoapHeaderBinding hb = ob as SoapHeaderBinding;
591 if (hb == null) continue;
592 if (HasHeader (OperationBinding.Output, hb))
593 ImportHeader (method, hb, SoapHeaderDirection.In | SoapHeaderDirection.Out);
595 ImportHeader (method, hb, SoapHeaderDirection.In);
598 if (OperationBinding.Output == null) return;
600 foreach (object ob in OperationBinding.Output.Extensions)
602 SoapHeaderBinding hb = ob as SoapHeaderBinding;
603 if (hb == null) continue;
604 if (!HasHeader (OperationBinding.Input, hb))
605 ImportHeader (method, hb, SoapHeaderDirection.Out);
609 bool HasHeader (MessageBinding msg, SoapHeaderBinding hb)
611 if (msg == null) return false;
613 foreach (object ob in msg.Extensions)
615 SoapHeaderBinding mhb = ob as SoapHeaderBinding;
616 if ((mhb != null) && (mhb.Message == hb.Message) && (mhb.Part == hb.Part))
622 void ImportHeader (CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction)
624 Message msg = ServiceDescriptions.GetMessage (hb.Message);
625 if (msg == null) throw new InvalidOperationException ("Message " + hb.Message + " not found");
626 MessagePart part = msg.Parts [hb.Part];
627 if (part == null) throw new InvalidOperationException ("Message part " + hb.Part + " not found in message " + hb.Message);
630 if (hb.Use == SoapBindingUse.Literal)
632 map = xmlImporter.ImportDerivedTypeMapping (part.Element, typeof (SoapHeader));
633 xmlExporter.ExportTypeMapping (map);
637 map = soapImporter.ImportDerivedTypeMapping (part.Type, typeof (SoapHeader), true);
638 soapExporter.ExportTypeMapping (map);
641 string varName = headerVariables [map] as string;
644 varName = memberIds.AddUnique(CodeIdentifier.MakeValid (map.TypeName + "Value"),hb);
645 headerVariables.Add (map, varName);
646 CodeMemberField codeField = new CodeMemberField (map.TypeFullName, varName);
647 codeField.Attributes = MemberAttributes.Public;
648 CodeTypeDeclaration.Members.Add (codeField);
651 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapHeaderAttribute");
652 att.Arguments.Add (GetArg (varName));
654 att.Arguments.Add (GetArg ("Required", false));
656 if (direction != SoapHeaderDirection.In) att.Arguments.Add (GetEnumArg ("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString ()));
657 AddCustomAttribute (method, att, true);
664 internal class Soap12ProtocolImporter : SoapProtocolImporter
666 public override string ProtocolName {
667 get { return "Soap12"; }
670 protected override bool IsBindingSupported ()
672 return Binding.Extensions.Find (typeof(Soap12Binding)) != null;