Forráskód Böngészése

Some XmlSerializerFormatAttribute and XmlSerializerOperationBehavior refactoring.

Atsushi Eno 14 éve
szülő
commit
852b7fe308

+ 9 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Description/ContractDescriptionGenerator.cs

@@ -283,6 +283,15 @@ namespace System.ServiceModel.Description
 				if (HasInvalidMessageContract (mi, oca.AsyncPattern))
 					throw new InvalidOperationException (String.Format ("The operation {0} contains more than one parameters and one or more of them are marked with MessageContractAttribute, but the attribute must be used within an operation that has only one parameter.", od.Name));
 
+#if !NET_2_1
+				var xfa = serviceMethod.GetCustomAttribute<XmlSerializerFormatAttribute> (false);
+				if (xfa != null)
+					od.Behaviors.Add (new XmlSerializerOperationBehavior (od, xfa));
+#endif
+				var dfa = serviceMethod.GetCustomAttribute<DataContractFormatAttribute> (false);
+				if (dfa != null)
+					od.Behaviors.Add (new DataContractSerializerOperationBehavior (od, dfa));
+
 				od.Messages.Add (GetMessage (od, mi, oca, true, isCallback, null));
 				if (!od.IsOneWay)
 					od.Messages.Add (GetMessage (od, mi, oca, false, isCallback, asyncReturnType));

+ 12 - 4
mcs/class/System.ServiceModel/System.ServiceModel.Description/XmlSerializerOperationBehavior.cs

@@ -53,6 +53,8 @@ namespace System.ServiceModel.Description
 			OperationDescription operation,
 			XmlSerializerFormatAttribute format)
 		{
+			if (operation == null)
+				throw new ArgumentNullException ("operation");
 			if (format == null)
 				format = new XmlSerializerFormatAttribute ();
 			this.format = format;
@@ -73,27 +75,33 @@ namespace System.ServiceModel.Description
 			OperationDescription description,
 			BindingParameterCollection parameters)
 		{
-			throw new NotImplementedException ();
 		}
 		
 		void IOperationBehavior.ApplyDispatchBehavior (
 			OperationDescription description,
 			DispatchOperation dispatch)
 		{
-			throw new NotImplementedException ();
+			if (description == null)
+				throw new ArgumentNullException ("description");
+			if (dispatch == null)
+				throw new ArgumentNullException ("dispatch");
+			dispatch.Formatter = new XmlMessagesFormatter (description, format);
 		}
 
 		void IOperationBehavior.ApplyClientBehavior (
 			OperationDescription description,
 			ClientOperation proxy)
 		{
-			throw new NotImplementedException ();
+			if (description == null)
+				throw new ArgumentNullException ("description");
+			if (proxy == null)
+				throw new ArgumentNullException ("proxy");
+			proxy.Formatter = new XmlMessagesFormatter (description, format);
 		}
 
 		void IOperationBehavior.Validate (
 			OperationDescription description)
 		{
-			throw new NotImplementedException ();
 		}
 
 #if !NET_2_1

+ 6 - 0
mcs/class/System.ServiceModel/System.ServiceModel.Dispatcher/BaseMessagesFormatter.cs

@@ -138,6 +138,12 @@ namespace System.ServiceModel.Dispatcher
 			operation_known_types.AddRange (desc.KnownTypes);
 		}
 
+		// FIXME: this should be refactored and eliminated.
+		// XmlSerializerFormatAttribute and DataContractFormatAttribute
+		// should be handled at ContractDescription.GetContract (to fill
+		// IOperationBehavior for each).
+		//
+		// Fixing the issue above should also fix "Formatter is already filled at initial state" issue described in EndpointDispatcher.cs and ContractDescription.cs.
 		public static BaseMessagesFormatter Create (OperationDescription desc)
 		{
 			MethodInfo attrProvider = desc.SyncMethod ?? desc.BeginMethod;