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);
109 codeClass.IsPartial = true;
111 string location = null;
114 SoapAddressBinding sab = (SoapAddressBinding) Port.Extensions.Find (typeof(SoapAddressBinding));
115 if (sab != null) location = sab.Location;
118 string namspace = (Port != null ? Port.Binding.Namespace : Binding.ServiceDescription.TargetNamespace);
119 string name = (Port != null ? Port.Name : Binding.Name);
121 if (Style == ServiceDescriptionImportStyle.Client) {
122 CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.Protocols.SoapHttpClientProtocol");
123 codeClass.BaseTypes.Add (ctr);
126 CodeTypeReference ctr = new CodeTypeReference ("System.Web.Services.WebService");
127 codeClass.BaseTypes.Add (ctr);
128 CodeAttributeDeclaration attws = new CodeAttributeDeclaration ("System.Web.Services.WebServiceAttribute");
129 attws.Arguments.Add (GetArg ("Namespace", namspace));
130 AddCustomAttribute (codeClass, attws, true);
133 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebServiceBinding");
134 att.Arguments.Add (GetArg ("Name", name));
135 att.Arguments.Add (GetArg ("Namespace", namspace));
136 AddCustomAttribute (codeClass, att, true);
138 if (Style == ServiceDescriptionImportStyle.Client) {
139 CodeConstructor cc = new CodeConstructor ();
140 cc.Attributes = MemberAttributes.Public;
141 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));
149 codeClass.Members.Add (cc);
152 memberIds = new CodeIdentifiers ();
153 headerVariables = new Hashtable ();
157 protected override void BeginNamespace ()
159 xmlImporter = new XmlSchemaImporter (LiteralSchemas, base.CodeGenerationOptions, base.CodeGenerator, base.ImportContext);
160 soapImporter = new SoapSchemaImporter (EncodedSchemas, base.CodeGenerationOptions, base.CodeGenerator, base.ImportContext);
161 xmlExporter = new XmlCodeExporter (CodeNamespace, null, base.CodeGenerator, base.CodeGenerationOptions, null);
162 soapExporter = new SoapCodeExporter (CodeNamespace, null, base.CodeGenerator, base.CodeGenerationOptions, null);
165 protected override void EndClass ()
167 SoapTransportImporter transportImporter = SoapTransportImporter.FindTransportImporter (soapBinding.Transport);
168 if (transportImporter == null) throw new InvalidOperationException ("Transport '" + soapBinding.Transport + "' not supported");
169 transportImporter.ImportContext = this;
170 transportImporter.ImportClass ();
172 if (xmlExporter.IncludeMetadata.Count > 0 || soapExporter.IncludeMetadata.Count > 0)
174 if (CodeTypeDeclaration.CustomAttributes == null)
175 CodeTypeDeclaration.CustomAttributes = new CodeAttributeDeclarationCollection ();
176 CodeTypeDeclaration.CustomAttributes.AddRange (xmlExporter.IncludeMetadata);
177 CodeTypeDeclaration.CustomAttributes.AddRange (soapExporter.IncludeMetadata);
181 protected override void EndNamespace ()
185 protected override bool IsBindingSupported ()
187 object o = Binding.Extensions.Find (typeof(SoapBinding));
188 return o != null && !(o is Soap12Binding);
192 protected override bool IsOperationFlowSupported (OperationFlow flow)
194 throw new NotImplementedException ();
197 static readonly char [] whitespaces = new char [] {' ', '\t', '\n', '\r'};
199 protected virtual bool IsSoapEncodingPresent (string uriList)
201 foreach (string s in uriList.Split (whitespaces))
202 if (s == "http://schemas.xmlsoap.org/soap/encoding/")
207 protected override CodeMemberMethod GenerateMethod ()
211 SoapOperationBinding soapOper = OperationBinding.Extensions.Find (typeof (SoapOperationBinding)) as SoapOperationBinding;
212 if (soapOper == null) throw new InvalidOperationException ("Soap operation binding not found");
214 SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style;
216 SoapBodyBinding isbb = null;
217 XmlMembersMapping inputMembers = null;
219 bool isWrapped = CheckIsWrapped ();
221 isbb = OperationBinding.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
222 if (isbb == null) throw new InvalidOperationException ("Soap body binding not found");
224 inputMembers = ImportMembersMapping (InputMessage, isbb, style, false, isWrapped);
225 if (inputMembers == null) throw new InvalidOperationException ("Input message not declared");
227 // If OperationBinding.Output is null, it is an OneWay operation
229 SoapBodyBinding osbb = null;
230 XmlMembersMapping outputMembers = null;
232 if (OperationBinding.Output != null) {
233 osbb = OperationBinding.Output.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
234 if (osbb == null) throw new InvalidOperationException ("Soap body binding not found");
236 outputMembers = ImportMembersMapping (OutputMessage, osbb, style, true, isWrapped);
237 if (outputMembers == null) throw new InvalidOperationException ("Output message not declared");
240 CodeMemberMethod met = GenerateMethod (memberIds, soapOper, isbb, inputMembers, outputMembers);
242 if (isbb.Use == SoapBindingUse.Literal)
243 xmlExporter.ExportMembersMapping (inputMembers);
245 soapExporter.ExportMembersMapping (inputMembers);
248 if (osbb.Use == SoapBindingUse.Literal)
249 xmlExporter.ExportMembersMapping (outputMembers);
251 soapExporter.ExportMembersMapping (outputMembers);
254 foreach (SoapExtensionImporter eximporter in extensionImporters)
256 eximporter.ImportContext = this;
257 eximporter.ImportMethod (met.CustomAttributes);
262 catch (InvalidOperationException ex)
264 UnsupportedOperationBindingWarning (ex.Message);
269 bool CheckIsWrapped ()
271 return (OutputMessage == null || (OutputMessage.Parts.Count == 1 && OutputMessage.Parts[0].Name == "parameters")) &&
272 (InputMessage == null || (InputMessage.Parts.Count == 1 && InputMessage.Parts[0].Name == "parameters"));
275 XmlMembersMapping ImportMembersMapping (Message msg, SoapBodyBinding sbb, SoapBindingStyle style, bool output, bool wrapped)
277 string elemName = Operation.Name;
278 if (output) elemName += "Response";
282 // Wrapped parameter style
284 MessagePart part = msg.Parts[0];
285 if (sbb.Use == SoapBindingUse.Encoded)
287 SoapSchemaMember ssm = new SoapSchemaMember ();
288 ssm.MemberName = part.Name;
289 ssm.MemberType = part.Type;
290 return soapImporter.ImportMembersMapping (elemName, part.Type.Namespace, ssm);
293 return xmlImporter.ImportMembersMapping (part.Element);
297 if (sbb.Use == SoapBindingUse.Encoded)
299 SoapSchemaMember[] mems = new SoapSchemaMember [msg.Parts.Count];
300 for (int n=0; n<mems.Length; n++)
302 SoapSchemaMember mem = new SoapSchemaMember();
303 mem.MemberName = msg.Parts[n].Name;
304 mem.MemberType = msg.Parts[n].Type;
308 // Rpc messages always have a wrapping element
309 if (style == SoapBindingStyle.Rpc)
310 return soapImporter.ImportMembersMapping (elemName, sbb.Namespace, mems, true);
312 return soapImporter.ImportMembersMapping ("", "", mems, false);
316 if (style == SoapBindingStyle.Rpc)
317 throw new InvalidOperationException ("The combination of style=rpc with use=literal is not supported");
319 if (msg.Parts.Count == 1 && msg.Parts[0].Type != XmlQualifiedName.Empty)
320 return xmlImporter.ImportAnyType (msg.Parts[0].Type, null);
323 XmlQualifiedName[] pnames = new XmlQualifiedName [msg.Parts.Count];
324 for (int n=0; n<pnames.Length; n++)
325 pnames[n] = msg.Parts[n].Element;
326 return xmlImporter.ImportMembersMapping (pnames);
332 CodeMemberMethod GenerateMethod (CodeIdentifiers memberIds, SoapOperationBinding soapOper, SoapBodyBinding bodyBinding, XmlMembersMapping inputMembers, XmlMembersMapping outputMembers)
334 CodeIdentifiers pids = new CodeIdentifiers ();
335 CodeMemberMethod method = new CodeMemberMethod ();
336 CodeMemberMethod methodBegin = new CodeMemberMethod ();
337 CodeMemberMethod methodEnd = new CodeMemberMethod ();
338 method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
339 methodBegin.Attributes = MemberAttributes.Public | MemberAttributes.Final;
340 methodEnd.Attributes = MemberAttributes.Public | MemberAttributes.Final;
342 SoapBindingStyle style = soapOper.Style != SoapBindingStyle.Default ? soapOper.Style : soapBinding.Style;
344 // Find unique names for temporary variables
346 for (int n=0; n<inputMembers.Count; n++)
347 pids.AddUnique (inputMembers[n].MemberName, inputMembers[n]);
349 if (outputMembers != null)
350 for (int n=0; n<outputMembers.Count; n++)
351 pids.AddUnique (outputMembers[n].MemberName, outputMembers[n]);
353 string varAsyncResult = pids.AddUnique ("asyncResult","asyncResult");
354 string varResults = pids.AddUnique ("results","results");
355 string varCallback = pids.AddUnique ("callback","callback");
356 string varAsyncState = pids.AddUnique ("asyncState","asyncState");
358 string messageName = memberIds.AddUnique(CodeIdentifier.MakeValid(Operation.Name),method);
360 method.Name = CodeIdentifier.MakeValid(Operation.Name);
361 if (method.Name == ClassName) method.Name += "1";
362 methodBegin.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("Begin" + method.Name),method);
363 methodEnd.Name = memberIds.AddUnique(CodeIdentifier.MakeValid("End" + method.Name),method);
365 method.ReturnType = new CodeTypeReference (typeof(void));
366 methodEnd.ReturnType = new CodeTypeReference (typeof(void));
367 methodEnd.Parameters.Add (new CodeParameterDeclarationExpression (typeof (IAsyncResult),varAsyncResult));
369 CodeExpression[] paramArray = new CodeExpression [inputMembers.Count];
370 CodeParameterDeclarationExpression[] outParams = new CodeParameterDeclarationExpression [outputMembers != null ? outputMembers.Count : 0];
372 for (int n=0; n<inputMembers.Count; n++)
374 CodeParameterDeclarationExpression param = GenerateParameter (inputMembers[n], FieldDirection.In);
375 method.Parameters.Add (param);
376 GenerateMemberAttributes (inputMembers, inputMembers[n], bodyBinding.Use, param);
377 methodBegin.Parameters.Add (GenerateParameter (inputMembers[n], FieldDirection.In));
378 paramArray [n] = new CodeVariableReferenceExpression (param.Name);
381 if (outputMembers != null)
383 bool hasReturn = false;
384 for (int n=0; n<outputMembers.Count; n++)
386 CodeParameterDeclarationExpression cpd = GenerateParameter (outputMembers[n], FieldDirection.Out);
390 foreach (CodeParameterDeclarationExpression ip in method.Parameters)
392 if (ip.Name == cpd.Name && ip.Type.BaseType == cpd.Type.BaseType) {
393 ip.Direction = FieldDirection.Ref;
394 methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
405 method.ReturnType = cpd.Type;
406 methodEnd.ReturnType = cpd.Type;
407 GenerateReturnAttributes (outputMembers, outputMembers[n], bodyBinding.Use, method);
408 outParams [n] = null;
412 method.Parameters.Add (cpd);
413 GenerateMemberAttributes (outputMembers, outputMembers[n], bodyBinding.Use, cpd);
414 methodEnd.Parameters.Add (GenerateParameter (outputMembers[n], FieldDirection.Out));
418 methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (AsyncCallback),varCallback));
419 methodBegin.Parameters.Add (new CodeParameterDeclarationExpression (typeof (object),varAsyncState));
420 methodBegin.ReturnType = new CodeTypeReference (typeof(IAsyncResult));
422 // Array of input parameters
424 CodeArrayCreateExpression methodParams;
425 if (paramArray.Length > 0)
426 methodParams = new CodeArrayCreateExpression (typeof(object), paramArray);
428 methodParams = new CodeArrayCreateExpression (typeof(object), 0);
430 // Assignment of output parameters
432 CodeStatementCollection outAssign = new CodeStatementCollection ();
433 CodeVariableReferenceExpression arrVar = new CodeVariableReferenceExpression (varResults);
434 for (int n=0; n<outParams.Length; n++)
436 CodeExpression index = new CodePrimitiveExpression (n);
437 if (outParams[n] == null)
439 CodeExpression res = new CodeCastExpression (method.ReturnType, new CodeArrayIndexerExpression (arrVar, index));
440 outAssign.Add (new CodeMethodReturnStatement (res));
444 CodeExpression res = new CodeCastExpression (outParams[n].Type, new CodeArrayIndexerExpression (arrVar, index));
445 CodeExpression var = new CodeVariableReferenceExpression (outParams[n].Name);
446 outAssign.Insert (0, new CodeAssignStatement (var, res));
450 if (Style == ServiceDescriptionImportStyle.Client)
454 CodeThisReferenceExpression ethis = new CodeThisReferenceExpression();
455 CodePrimitiveExpression varMsgName = new CodePrimitiveExpression (messageName);
456 CodeMethodInvokeExpression inv;
457 CodeVariableDeclarationStatement dec;
459 inv = new CodeMethodInvokeExpression (ethis, "Invoke", varMsgName, methodParams);
460 if (outputMembers != null && outputMembers.Count > 0)
462 dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
463 method.Statements.Add (dec);
464 method.Statements.AddRange (outAssign);
467 method.Statements.Add (inv);
471 CodeExpression expCallb = new CodeVariableReferenceExpression (varCallback);
472 CodeExpression expAsyncs = new CodeVariableReferenceExpression (varAsyncState);
473 inv = new CodeMethodInvokeExpression (ethis, "BeginInvoke", varMsgName, methodParams, expCallb, expAsyncs);
474 methodBegin.Statements.Add (new CodeMethodReturnStatement (inv));
478 CodeExpression varAsyncr = new CodeVariableReferenceExpression (varAsyncResult);
479 inv = new CodeMethodInvokeExpression (ethis, "EndInvoke", varAsyncr);
480 if (outputMembers != null && outputMembers.Count > 0)
482 dec = new CodeVariableDeclarationStatement (typeof(object[]), varResults, inv);
483 methodEnd.Statements.Add (dec);
484 methodEnd.Statements.AddRange (outAssign);
487 methodEnd.Statements.Add (inv);
490 method.Attributes = MemberAttributes.Public | MemberAttributes.Abstract;
495 ImportHeaders (method);
497 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.WebMethodAttribute");
498 if (messageName != method.Name) att.Arguments.Add (GetArg ("MessageName",messageName));
499 AddCustomAttribute (method, att, (Style == ServiceDescriptionImportStyle.Server));
501 if (style == SoapBindingStyle.Rpc)
503 att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapRpcMethodAttribute");
504 att.Arguments.Add (GetArg (soapOper.SoapAction));
505 if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
506 if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
507 att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
508 if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
509 if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
513 if (outputMembers != null && (inputMembers.ElementName == "" && outputMembers.ElementName != "" ||
514 inputMembers.ElementName != "" && outputMembers.ElementName == ""))
515 throw new InvalidOperationException ("Parameter style is not the same for the input message and output message");
517 att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapDocumentMethodAttribute");
518 att.Arguments.Add (GetArg (soapOper.SoapAction));
519 if (inputMembers.ElementName != "") {
520 if (inputMembers.ElementName != method.Name) att.Arguments.Add (GetArg ("RequestElementName", inputMembers.ElementName));
521 if (outputMembers != null && outputMembers.ElementName != (method.Name + "Response")) att.Arguments.Add (GetArg ("ResponseElementName", outputMembers.ElementName));
522 att.Arguments.Add (GetArg ("RequestNamespace", inputMembers.Namespace));
523 if (outputMembers != null) att.Arguments.Add (GetArg ("ResponseNamespace", outputMembers.Namespace));
524 att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Wrapped"));
527 att.Arguments.Add (GetEnumArg ("ParameterStyle", "System.Web.Services.Protocols.SoapParameterStyle", "Bare"));
529 if (outputMembers == null) att.Arguments.Add (GetArg ("OneWay", true));
531 att.Arguments.Add (GetEnumArg ("Use", "System.Web.Services.Description.SoapBindingUse", bodyBinding.Use.ToString()));
534 AddCustomAttribute (method, att, true);
536 CodeTypeDeclaration.Members.Add (method);
538 if (Style == ServiceDescriptionImportStyle.Client) {
539 CodeTypeDeclaration.Members.Add (methodBegin);
540 CodeTypeDeclaration.Members.Add (methodEnd);
546 CodeParameterDeclarationExpression GenerateParameter (XmlMemberMapping member, FieldDirection dir)
548 string type = member.GenerateTypeName (CodeGenerator);
549 CodeParameterDeclarationExpression par = new CodeParameterDeclarationExpression (type, member.MemberName);
554 void GenerateMemberAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeParameterDeclarationExpression param)
556 if (use == SoapBindingUse.Literal)
557 xmlExporter.AddMappingMetadata (param.CustomAttributes, member, members.Namespace);
559 soapExporter.AddMappingMetadata (param.CustomAttributes, member);
562 void GenerateReturnAttributes (XmlMembersMapping members, XmlMemberMapping member, SoapBindingUse use, CodeMemberMethod method)
564 if (use == SoapBindingUse.Literal)
565 xmlExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, members.Namespace, (member.ElementName != method.Name + "Result"));
567 soapExporter.AddMappingMetadata (method.ReturnTypeCustomAttributes, member, (member.ElementName != method.Name + "Result"));
570 void ImportHeaders (CodeMemberMethod method)
572 foreach (object ob in OperationBinding.Input.Extensions)
574 SoapHeaderBinding hb = ob as SoapHeaderBinding;
575 if (hb == null) continue;
576 if (HasHeader (OperationBinding.Output, hb))
577 ImportHeader (method, hb, SoapHeaderDirection.In | SoapHeaderDirection.Out);
579 ImportHeader (method, hb, SoapHeaderDirection.In);
582 if (OperationBinding.Output == null) return;
584 foreach (object ob in OperationBinding.Output.Extensions)
586 SoapHeaderBinding hb = ob as SoapHeaderBinding;
587 if (hb == null) continue;
588 if (!HasHeader (OperationBinding.Input, hb))
589 ImportHeader (method, hb, SoapHeaderDirection.Out);
593 bool HasHeader (MessageBinding msg, SoapHeaderBinding hb)
595 if (msg == null) return false;
597 foreach (object ob in msg.Extensions)
599 SoapHeaderBinding mhb = ob as SoapHeaderBinding;
600 if ((mhb != null) && (mhb.Message == hb.Message) && (mhb.Part == hb.Part))
606 void ImportHeader (CodeMemberMethod method, SoapHeaderBinding hb, SoapHeaderDirection direction)
608 Message msg = ServiceDescriptions.GetMessage (hb.Message);
609 if (msg == null) throw new InvalidOperationException ("Message " + hb.Message + " not found");
610 MessagePart part = msg.Parts [hb.Part];
611 if (part == null) throw new InvalidOperationException ("Message part " + hb.Part + " not found in message " + hb.Message);
615 if (hb.Use == SoapBindingUse.Literal)
617 map = xmlImporter.ImportDerivedTypeMapping (part.Element, typeof (SoapHeader));
618 hname = part.Element.Name;
619 xmlExporter.ExportTypeMapping (map);
623 map = soapImporter.ImportDerivedTypeMapping (part.Type, typeof (SoapHeader), true);
624 hname = part.Type.Name;
625 soapExporter.ExportTypeMapping (map);
628 string varName = headerVariables [map] as string;
631 if (hname == map.TypeName)
632 varName = memberIds.AddUnique(CodeIdentifier.MakeValid (hname + "Value"),hb);
634 varName = memberIds.AddUnique(CodeIdentifier.MakeValid (hname),hb);
636 string propName = varName;
637 varName = varName + "Field";
638 headerVariables.Add (map, varName);
639 CodeMemberField codeField = new CodeMemberField (map.TypeFullName, varName);
640 CodeTypeDeclaration.Members.Add (codeField);
642 codeField.Attributes = MemberAttributes.Private;
643 CodeMemberProperty codeProperty = new CodeMemberProperty ();
644 codeProperty.Name = propName;
645 codeProperty.Type = new CodeTypeReference (map.TypeFullName);
646 codeProperty.Attributes = MemberAttributes.Public | MemberAttributes.Final;
647 codeProperty.HasGet = codeProperty.HasSet = true;
648 CodeExpression ce = new CodeFieldReferenceExpression (new CodeThisReferenceExpression(), varName);
649 codeProperty.SetStatements.Add (new CodeAssignStatement (ce, new CodePropertySetValueReferenceExpression()));
650 codeProperty.GetStatements.Add (new CodeMethodReturnStatement (ce));
651 CodeTypeDeclaration.Members.Add (codeProperty);
656 CodeAttributeDeclaration att = new CodeAttributeDeclaration ("System.Web.Services.Protocols.SoapHeaderAttribute");
657 att.Arguments.Add (GetArg (varName));
659 att.Arguments.Add (GetArg ("Required", false));
661 if (direction != SoapHeaderDirection.In) att.Arguments.Add (GetEnumArg ("Direction", "System.Web.Services.Protocols.SoapHeaderDirection", direction.ToString ()));
662 AddCustomAttribute (method, att, true);
668 internal class Soap12ProtocolImporter : SoapProtocolImporter
670 public override string ProtocolName {
671 get { return "Soap12"; }
674 protected override bool IsBindingSupported ()
676 return Binding.Extensions.Find (typeof(Soap12Binding)) != null;