HttpSimpleProtocolReflector.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // System.Web.Services.Description.HttpSimpleProtocolReflector.cs
  3. //
  4. // Author:
  5. // Lluis Sanchez Gual ([email protected])
  6. //
  7. // (C) 2003 Ximian, Inc.
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Web.Services;
  30. using System.Web.Services.Protocols;
  31. using System.Xml.Serialization;
  32. using System.Xml;
  33. using System.Xml.Schema;
  34. using System.Reflection;
  35. namespace System.Web.Services.Description {
  36. internal abstract class HttpSimpleProtocolReflector : ProtocolReflector
  37. {
  38. #region Fields
  39. SoapBinding soapBinding;
  40. #endregion // Fields
  41. #region Constructors
  42. public HttpSimpleProtocolReflector ()
  43. {
  44. }
  45. #endregion // Constructors
  46. #region Methods
  47. protected override void BeginClass ()
  48. {
  49. HttpAddressBinding abind = new HttpAddressBinding ();
  50. abind.Location = ServiceUrl;
  51. Port.Extensions.Add (abind);
  52. }
  53. protected override void EndClass ()
  54. {
  55. }
  56. protected override bool ReflectMethod ()
  57. {
  58. LogicalTypeInfo ti = TypeStubManager.GetLogicalTypeInfo (ServiceType);
  59. HttpOperationBinding sob = new HttpOperationBinding();
  60. sob.Location = "/" + MethodStubInfo.Name;
  61. OperationBinding.Extensions.Add (sob);
  62. if (!Method.IsVoid)
  63. {
  64. MimeXmlBinding mxb = new MimeXmlBinding ();
  65. mxb.Part = "Body";
  66. OperationBinding.Output.Extensions.Add (mxb);
  67. MessagePart part = new MessagePart ();
  68. part.Name = "Body";
  69. XmlTypeMapping map = ReflectionImporter.ImportTypeMapping (Method.ReturnType, ti.GetWebServiceLiteralNamespace (ServiceDescription.TargetNamespace));
  70. XmlQualifiedName qname = new XmlQualifiedName (map.ElementName, map.Namespace);
  71. part.Element = qname;
  72. OutputMessage.Parts.Add (part);
  73. SchemaExporter.ExportTypeMapping (map);
  74. }
  75. XmlReflectionMember[] mems = new XmlReflectionMember [Method.Parameters.Length];
  76. for (int n=0; n<Method.Parameters.Length; n++)
  77. {
  78. ParameterInfo param = Method.Parameters [n];
  79. XmlReflectionMember mem = new XmlReflectionMember ();
  80. mem.MemberName = param.Name;
  81. Type ptype = param.ParameterType;
  82. if (ptype.IsByRef) ptype = ptype.GetElementType ();
  83. mem.MemberType = ptype;
  84. mems [n] = mem;
  85. }
  86. XmlMembersMapping memap = ReflectionImporter.ImportMembersMapping ("", ti.WebServiceAbstractNamespace, mems, false);
  87. bool allPrimitives = true;
  88. for (int n=0; n<memap.Count; n++)
  89. {
  90. XmlMemberMapping mem = memap[n];
  91. MessagePart part = new MessagePart ();
  92. XmlQualifiedName pqname;
  93. if (mem.TypeNamespace == "")
  94. pqname = new XmlQualifiedName (mem.TypeName, XmlSchema.Namespace);
  95. else {
  96. pqname = new XmlQualifiedName (mem.TypeName, mem.TypeNamespace);
  97. allPrimitives = false;
  98. }
  99. part.Type = pqname;
  100. part.Name = mem.ElementName;
  101. InputMessage.Parts.Add (part);
  102. }
  103. if (!allPrimitives)
  104. SoapSchemaExporter.ExportMembersMapping (memap);
  105. return true;
  106. }
  107. XmlQualifiedName GenerateStringArray ()
  108. {
  109. return null;
  110. }
  111. protected override string ReflectMethodBinding ()
  112. {
  113. return null;
  114. }
  115. #endregion
  116. }
  117. }