public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch) { if (description == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); } if (dispatch == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("dispatch"); } if (dispatch.Parent == null || dispatch.Parent.ChannelDispatcher == null || dispatch.Parent.ChannelDispatcher.Host == null || dispatch.Parent.ChannelDispatcher.Host.Description == null || dispatch.Parent.ChannelDispatcher.Host.Description.Behaviors == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.DispatchOperationInInvalidState))); } WorkflowRuntimeBehavior workflowRuntimeBehavior = dispatch.Parent.ChannelDispatcher.Host.Description.Behaviors.Find<WorkflowRuntimeBehavior>(); if (workflowRuntimeBehavior == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.NoWorkflowRuntimeBehavior))); } dispatch.Invoker = new WorkflowOperationInvoker(description, this, workflowRuntimeBehavior.WorkflowRuntime, dispatch.Parent); }
internal FormDataRequestFormatter( OperationDescription operation ) { if (operation.BeginMethod != null || operation.EndMethod != null) throw new InvalidOperationException("The async programming model is not supported by this formatter."); this.operation = operation; }
public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch) { var dataContractSerializerOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); dataContractSerializerOperationBehavior.DataContractResolver = new ProxyDataContractResolver(); }
void IOperationBehavior.ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { ZipCodeInspector zipCodeInspector = new ZipCodeInspector(); clientOperation.ParameterInspectors.Add(zipCodeInspector); }
public XmlSerializerOperationFormatter(OperationDescription description, XmlSerializerFormatAttribute xmlSerializerFormatAttribute, MessageInfo requestMessageInfo, MessageInfo replyMessageInfo) : base(description, xmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc, false/*isEncoded*/) { _requestMessageInfo = requestMessageInfo; _replyMessageInfo = replyMessageInfo; }
protected MessageContractExporter(WsdlExporter exporter, WsdlContractConversionContext context, OperationDescription operation, IOperationBehavior extension) { this.exporter = exporter; this.contractContext = context; this.operation = operation; this.extension = extension; }
public DefaultJsonSerializerOperationBehavior(OperationDescription operation, bool isCompress, SerializeContentTypes contentType) : base(operation) { m_IsCompress = isCompress; m_ContentType = contentType; }
public void ApplyClientBehavior(OperationDescription description, System.ServiceModel.Dispatcher.ClientOperation proxy) { IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description); innerBehavior.ApplyClientBehavior(description, proxy); }
public void ApplyDispatchBehavior(OperationDescription description, System.ServiceModel.Dispatcher.DispatchOperation dispatch) { IOperationBehavior innerBehavior = new ReferencePreservingDataContractSerializerOperationBehavior(description); innerBehavior.ApplyDispatchBehavior(description, dispatch); }
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { var behavior = operationDescription.DeclaringContract.Behaviors.Find <WebDispatchFormatterConfigurationBehavior>(); if (behavior == null) behavior = dispatchOperation.Parent.ChannelDispatcher.Host.Description.Behaviors.Find <WebDispatchFormatterConfigurationBehavior>(); if (behavior == null) { var configurationAttribute = operationDescription.DeclaringContract.GetAttribute<WebDispatchFormatterConfigurationAttribute>(); if (configurationAttribute == null) configurationAttribute = dispatchOperation.Parent.ChannelDispatcher.Host.Description. GetAttribute<WebDispatchFormatterConfigurationAttribute>(); string defaultMimeType = null; if (configurationAttribute != null) defaultMimeType = configurationAttribute.DefaultMimeType; var mimeTypeAttributes = operationDescription.DeclaringContract.GetAttributes<WebDispatchFormatterMimeTypeAttribute>(); if (mimeTypeAttributes == null || mimeTypeAttributes.Count == 0) mimeTypeAttributes = dispatchOperation.Parent.ChannelDispatcher.Host.Description. GetAttributes<WebDispatchFormatterMimeTypeAttribute>(); var formatters = new Dictionary<string, Type>(); if (mimeTypeAttributes != null && mimeTypeAttributes.Count > 0) { foreach (var mimeTypeAttribute in mimeTypeAttributes) foreach (var mimeType in mimeTypeAttribute.MimeTypes) { if (defaultMimeType == null) defaultMimeType = mimeType; formatters.Add(mimeType, mimeTypeAttribute.Type); } } if (formatters.Count > 0) behavior = new WebDispatchFormatterConfigurationBehavior( formatters, defaultMimeType); } if (behavior == null) throw new ConfigurationErrorsException( "WebDispatchFormatterConfigurationBehavior or WebDispatchFormatterMimeTypeAttribute's not applied to contract or service. This behavior or attributes are required to configure web dispatch formatting."); dispatchOperation.Formatter = new WebDispatchFormatter( behavior.FormatterFactory, operationDescription, _direction != WebDispatchFormatter.FormatterDirection.Both ? dispatchOperation.Formatter : null, _direction); }
protected override IClientMessageFormatter GetRequestClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { if (operationDescription.Behaviors.Find<WebGetAttribute>() != null) { // no change for GET operations return base.GetRequestClientFormatter(operationDescription, endpoint); } else { WebInvokeAttribute wia = operationDescription.Behaviors.Find<WebInvokeAttribute>(); if (wia != null) { if (wia.Method == "HEAD") { // essentially a GET operation return base.GetRequestClientFormatter(operationDescription, endpoint); } } } if (operationDescription.Messages[0].Body.Parts.Count == 0) { // nothing in the body, still use the default return base.GetRequestClientFormatter(operationDescription, endpoint); } return new NewtonsoftJsonClientFormatter(operationDescription, endpoint); }
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { var behavior = operationDescription.DeclaringContract.FindBehavior <WebAuthenticationConfigurationBehavior, WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior) ?? dispatchOperation.Parent.ChannelDispatcher.Host.Description.FindBehavior <WebAuthenticationConfigurationBehavior, WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior); if (behavior == null) throw new ConfigurationErrorsException( "OperationAuthenticationConfigurationBehavior not applied to contract or service. This behavior is required to configure operation authentication."); var authorizationBehavior = operationDescription.DeclaringContract.FindBehavior <WebAuthorizationConfigurationBehavior, WebAuthorizationConfigurationAttribute>(b => b.BaseBehavior); Type authorizationPolicy = null; if (authorizationBehavior != null) authorizationPolicy = authorizationBehavior.AuthorizationPolicyType; dispatchOperation.Invoker = new OperationAuthenticationInvoker( dispatchOperation.Invoker, behavior.ThrowIfNull().AuthenticationHandler, behavior.UsernamePasswordValidatorType, behavior.RequireSecureTransport, behavior.Source, authorizationPolicy); }
public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) { //see if ChunkingBindingParameter already exists ChunkingBindingParameter param = parameters.Find<ChunkingBindingParameter>(); if (param == null) { param = new ChunkingBindingParameter(); parameters.Add(param); } if ((appliesTo & ChunkingAppliesTo.InMessage) == ChunkingAppliesTo.InMessage) { //add input message's action to ChunkingBindingParameter param.AddAction(description.Messages[0].Action); } if (!description.IsOneWay && ((appliesTo & ChunkingAppliesTo.OutMessage) == ChunkingAppliesTo.OutMessage)) { //add output message's action to ChunkingBindingParameter param.AddAction(description.Messages[1].Action); } }
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { Console.WriteLine("{0}: ", clientOperation.Name); IClientMessageFormatter formatter = clientOperation.Formatter; Console.WriteLine("\t{0}", formatter.GetType().Name); if (formatter.GetType().Name != "CompositeClientFormatter") { return; } object innerFormatter = this.GetField(formatter, "request"); Console.WriteLine("\t\t{0}", innerFormatter.GetType().Name); if (innerFormatter.GetType().Name == "UriTemplateClientFormatter") { innerFormatter = this.GetField(innerFormatter, "inner"); Console.WriteLine("\t\t\t{0}", innerFormatter.GetType().Name); return; } if (innerFormatter.GetType().Name == "ContentTypeSettingClientMessageFormatter") { innerFormatter = this.GetField(innerFormatter, "innerFormatter"); Console.WriteLine("\t\t\t{0}", innerFormatter.GetType().Name); if (innerFormatter.GetType().Name == "UriTemplateClientFormatter") { innerFormatter = this.GetField(innerFormatter, "inner"); Console.WriteLine("\t\t\t\t{0}", innerFormatter.GetType().Name); } } }
private void ValidateOperation(OperationDescription operation) { if (operation.Messages.Count > 1) { if (operation.Messages[1].Body.Parts.Count > 0) { throw new InvalidOperationException("Operations cannot have out/ref parameters."); } } WebMessageBodyStyle bodyStyle = this.GetBodyStyle(operation); int inputParameterCount = operation.Messages[0].Body.Parts.Count; if (!this.IsGetOperation(operation)) { var wrappedRequest = bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedRequest; if (inputParameterCount == 1 && wrappedRequest) { throw new InvalidOperationException("Wrapped body style for single parameters not implemented in this behavior."); } } var wrappedResponse = bodyStyle == WebMessageBodyStyle.Wrapped || bodyStyle == WebMessageBodyStyle.WrappedResponse; var isVoidReturn = operation.Messages.Count == 1 || operation.Messages[1].Body.ReturnValue.Type == typeof(void); if (!isVoidReturn && wrappedResponse) { throw new InvalidOperationException("Wrapped response not implemented in this behavior."); } }
public void Validate(OperationDescription operationDescription) { List<ParameterInfo> parameters; ParameterInfo returnValue; if (operationDescription.SyncMethod != null) { parameters = new List<ParameterInfo>(operationDescription.SyncMethod.GetParameters()); returnValue = operationDescription.SyncMethod.ReturnParameter; } else if (operationDescription.BeginMethod != null && operationDescription.EndMethod != null) { parameters = new List<ParameterInfo>(operationDescription.BeginMethod.GetParameters()); parameters.RemoveRange(parameters.Count - 2, 2); returnValue = operationDescription.EndMethod.ReturnParameter; } else { throw new InvalidOperationException(); } foreach (ParameterInfo param in parameters) { if (param.IsOut) { throw new InvalidOperationException(); } ValidateXmlRpcType(param.ParameterType); } if (returnValue != null) { ValidateXmlRpcType(returnValue.ParameterType); } }
void IOperationBehavior.ApplyDispatchBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.DispatchOperation dispatchOperation) { if (IsAuthenticationEnabled) { dispatchOperation.ParameterInspectors.Add(this); } }
public void Deserialize(OperationDescription operation, Dictionary<string, int> parameterNames, Message message, object[] parameters) { object bodyFormatProperty; if (!message.Properties.TryGetValue(WebBodyFormatMessageProperty.Name, out bodyFormatProperty) || (bodyFormatProperty as WebBodyFormatMessageProperty).Format != WebContentFormat.Raw) { throw new InvalidOperationException( "Incoming messages must have a body format of Raw. Is a ContentTypeMapper set on the WebHttpBinding?"); } var bodyReader = message.GetReaderAtBodyContents(); bodyReader.ReadStartElement("Binary"); byte[] rawBody = bodyReader.ReadContentAsBase64(); using (var ms = new MemoryStream(rawBody)) using (var sr = new StreamReader(ms)) { var serializer = new System.Xml.Serialization.XmlSerializer(operation.Messages[0].Body.Parts[0].Type); if (parameters.Length == 1) { // single parameter, assuming bare parameters[0] = serializer.Deserialize(sr); } else { throw new InvalidOperationException("We don't support multiple xml parameters"); } sr.Close(); ms.Close(); } }
// ────────────────────────── IOperationBehavior Members ────────────────────────── public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { var behavior = operationDescription.DeclaringContract.FindBehavior <OAuthAuthenticationConfigurationBehavior, OAuthAuthenticationConfigurationAttribute>(b => b.BaseBehavior); if (behavior == null) behavior = dispatchOperation.Parent.ChannelDispatcher.Host.Description.FindBehavior <OAuthAuthenticationConfigurationBehavior, OAuthAuthenticationConfigurationAttribute>(b => b.BaseBehavior); if (behavior == null) throw new ConfigurationErrorsException( "OperationAuthenticationConfigurationBehavior not applied to contract or service. This behavior is required to configure operation authentication."); var scopeToUse = string.IsNullOrWhiteSpace(this.Scope) ? behavior.Scope : this.Scope; dispatchOperation.Invoker = new OperationOAuthAuthenticationInvoker( dispatchOperation.Invoker, behavior.AuthenticationHandler, behavior.RequireSecureTransport, scopeToUse, AllowAnonymous); }
public void ApplyClientBehavior(OperationDescription operationDescription, ClientOperation clientOperation) { clientOperation.Formatter = new RestClientMessageFormatter(clientOperation.Formatter , operationDescription , this.Mapper , this.Configuration); }
/// <summary> /// Add the Ping method to the existing contract /// </summary> private void AddPingToContractDescription(ContractDescription contractDescription) { OperationDescription pingOperationDescription = new OperationDescription(PingOperationName, contractDescription); MessageDescription inputMessageDescription = new MessageDescription( GetAction(contractDescription, PingOperationName), MessageDirection.Input); MessageDescription outputMessageDescription = new MessageDescription( GetAction(contractDescription, PingResponse), MessageDirection.Output); MessagePartDescription returnValue = new MessagePartDescription("PingResult", contractDescription.Namespace); returnValue.Type = typeof(DateTime); outputMessageDescription.Body.ReturnValue = returnValue; inputMessageDescription.Body.WrapperName = PingOperationName; inputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace; outputMessageDescription.Body.WrapperName = PingResponse; outputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace; pingOperationDescription.Messages.Add(inputMessageDescription); pingOperationDescription.Messages.Add(outputMessageDescription); pingOperationDescription.Behaviors.Add(new DataContractSerializerOperationBehavior(pingOperationDescription)); pingOperationDescription.Behaviors.Add(new PingOperationBehavior()); contractDescription.Operations.Add(pingOperationDescription); }
/// <summary> /// Create a new ProtoOperationBehavior instance /// </summary> public ProtoOperationBehavior(OperationDescription operation) : base(operation) { #if !NO_RUNTIME model = RuntimeTypeModel.Default; #endif }
public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy) { var dataContractSerializerOperationBehavior = description.Behaviors.Find<DataContractSerializerOperationBehavior>(); dataContractSerializerOperationBehavior.DataContractResolver = new ProxyDataContractResolver(); }
internal override void InferMessageDescription(OperationDescription operation, object owner, MessageDirection direction) { ContractInferenceHelper.CheckForDisposableParameters(operation, this.InternalDeclaredMessageType); string overridingAction = null; SerializerOption dataContractSerializer = SerializerOption.DataContractSerializer; Receive receive = owner as Receive; if (receive != null) { overridingAction = receive.Action; dataContractSerializer = receive.SerializerOption; } else { ReceiveReply reply = owner as ReceiveReply; overridingAction = reply.Action; dataContractSerializer = reply.Request.SerializerOption; } if (direction == MessageDirection.Input) { ContractInferenceHelper.AddInputMessage(operation, overridingAction, this.InternalDeclaredMessageType, dataContractSerializer); } else { ContractInferenceHelper.AddOutputMessage(operation, overridingAction, this.InternalDeclaredMessageType, dataContractSerializer); } }
public DataContractSerializerOperationFormatter(OperationDescription description, DataContractFormatAttribute dataContractFormatAttribute, DataContractSerializerOperationBehavior serializerFactory) : base(description, dataContractFormatAttribute.Style == OperationFormatStyle.Rpc, false) { if (description == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); } this.serializerFactory = serializerFactory ?? new DataContractSerializerOperationBehavior(description); foreach (System.Type type in description.KnownTypes) { if (this.knownTypes == null) { this.knownTypes = new List<System.Type>(); } if (type == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("SFxKnownTypeNull", new object[] { description.Name }))); } this.ValidateDataContractType(type); this.knownTypes.Add(type); } this.requestMessageInfo = this.CreateMessageInfo(dataContractFormatAttribute, base.RequestDescription, this.serializerFactory); if (base.ReplyDescription != null) { this.replyMessageInfo = this.CreateMessageInfo(dataContractFormatAttribute, base.ReplyDescription, this.serializerFactory); } }
private static void TryGetSurrogateBehavior(OperationDescription operationDescription, ref IOperationBehavior original, ref IOperationBehavior surrogate) { if (!IsUntypedMessage(operationDescription.Messages[0]) && operationDescription.Messages[0].Body.Parts.Count != 0) { var webGetAttribute = operationDescription.Behaviors.Find<WebGetAttribute>(); if (webGetAttribute != null) { original = webGetAttribute; surrogate = new WebInvokeAttribute { BodyStyle = webGetAttribute.BodyStyle, Method = "NONE", RequestFormat = webGetAttribute.RequestFormat, ResponseFormat = webGetAttribute.ResponseFormat, UriTemplate = webGetAttribute.UriTemplate }; } else { var webInvokeAttribute = operationDescription.Behaviors.Find<WebInvokeAttribute>(); if (webInvokeAttribute != null && webInvokeAttribute.Method == "GET") { original = webInvokeAttribute; surrogate = new WebInvokeAttribute { BodyStyle = webInvokeAttribute.BodyStyle, Method = "NONE", RequestFormat = webInvokeAttribute.RequestFormat, ResponseFormat = webInvokeAttribute.ResponseFormat, UriTemplate = webInvokeAttribute.UriTemplate }; } } } }
public void Validate(OperationDescription operationDescription) { if (operationDescription.Messages.Count < 2 || operationDescription.Messages[1].Body.ReturnValue.Type != typeof(double)) { throw new InvalidOperationException("This behavior can only be applied on operation which returns double"); } }
public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation runtime) { if (_runtime == runtime.Parent) { runtime.Formatter = new BinaryFormatterAdapter(description.Name, description.SyncMethod.GetParameters(), runtime.Formatter); } }
static void FillOperation(IWmiInstance operation, OperationDescription operationDescription) { operation.SetProperty(AdministrationStrings.Name, operationDescription.Name); operation.SetProperty(AdministrationStrings.Action, FixWildcardAction(operationDescription.Messages[0].Action)); if (operationDescription.Messages.Count > 1) { operation.SetProperty(AdministrationStrings.ReplyAction, FixWildcardAction(operationDescription.Messages[1].Action)); } operation.SetProperty(AdministrationStrings.IsOneWay, operationDescription.IsOneWay); operation.SetProperty(AdministrationStrings.IsInitiating, operationDescription.IsInitiating); operation.SetProperty(AdministrationStrings.IsTerminating, operationDescription.IsTerminating); operation.SetProperty(AdministrationStrings.AsyncPattern, null != operationDescription.BeginMethod); if (null != operationDescription.SyncMethod) { if (null != operationDescription.SyncMethod.ReturnType) { operation.SetProperty(AdministrationStrings.ReturnType, operationDescription.SyncMethod.ReturnType.Name); } operation.SetProperty(AdministrationStrings.MethodSignature, operationDescription.SyncMethod.ToString()); ParameterInfo[] parameterInfo = operationDescription.SyncMethod.GetParameters(); string[] parameterTypes = new string[parameterInfo.Length]; for (int i = 0; i < parameterInfo.Length; i++) { parameterTypes[i] = parameterInfo[i].ParameterType.ToString(); } operation.SetProperty(AdministrationStrings.ParameterTypes, parameterTypes); } operation.SetProperty(AdministrationStrings.IsCallback, operationDescription.Messages[0].Direction == MessageDirection.Output); FillBehaviorsInfo(operation, operationDescription.Behaviors); }
public void ApplyClientBehavior(OperationDescription operationDescription, System.ServiceModel.Dispatcher.ClientOperation clientOperation) { Contract.Requires(clientOperation != null); Contract.Requires(clientOperation.Formatter != null); clientOperation.Formatter = new CollectionIsListMessageFormatter(clientOperation.Formatter); }
protected virtual QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription) { return(new QueryStringConverter()); }
protected virtual IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { return(new WebMessageFormatter.RequestDispatchFormatter(operationDescription, endpoint, GetQueryStringConverter(operationDescription), this)); }
public OperationInfo(System.ServiceModel.Activities.Receive receive, System.ServiceModel.Description.OperationDescription operationDescription) { this.receive = receive; this.operationDescription = operationDescription; }
protected void ValidateOperation(OperationDescription operation) { var wai = operation.GetWebAttributeInfo(); if (wai.Method == "GET") { return; } var style = GetBodyStyle(wai); // if the style is wrapped there won't be problems if (style == WebMessageBodyStyle.Wrapped) { return; } string [] parameters; if (wai.UriTemplate != null) { // find all variables in the URI var uri = new UriTemplate(wai.UriTemplate); parameters = new string [uri.PathSegmentVariableNames.Count + uri.QueryValueVariableNames.Count]; uri.PathSegmentVariableNames.CopyTo(parameters, 0); uri.QueryValueVariableNames.CopyTo(parameters, uri.PathSegmentVariableNames.Count); // sort because Array.BinarySearch is the easiest way for case-insensitive search Array.Sort(parameters, StringComparer.InvariantCultureIgnoreCase); } else { parameters = new string [0]; } bool hasBody = false; foreach (var msg in operation.Messages) { if (msg.Direction == MessageDirection.Input) { // the message is for a request // if requests are wrapped there is nothing to check if (style == WebMessageBodyStyle.WrappedRequest) { continue; } foreach (var part in msg.Body.Parts) { if (Array.BinarySearch(parameters, part.Name, StringComparer.InvariantCultureIgnoreCase) < 0) { // this part of the message is not covered by a variable in the URI // so it must be passed in the body if (hasBody) { throw new InvalidOperationException(String.Format("Operation '{0}' has multiple message body parts. Add parameters to the UriTemplate or change the BodyStyle to 'Wrapped' or 'WrappedRequest' on the WebInvoke/WebGet attribute.", operation.Name)); } hasBody = true; } } } else { // the message is for a response if (style != WebMessageBodyStyle.WrappedResponse && msg.Body.Parts.Count > 0) { throw new InvalidOperationException(String.Format("Operation '{0}' has output parameters. BodyStyle must be 'Wrapped' or 'WrappedResponse' on the operation WebInvoke/WebGet attribute.", operation.Name)); } } } }
public Operation GetOperation(OperationDescription operation) { throw new NotImplementedException(); }
protected virtual IClientMessageFormatter GetReplyClientFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { return(new WebMessageFormatter.ReplyClientFormatter(operationDescription, endpoint, GetQueryStringConverter(operationDescription), this)); }
// -------------------------------------------------------------------------------------------------- internal void AddOperation(OperationDescription operationDescription, WsdlNS.Operation wsdlOperation) { this.wsdlOperations.Add(operationDescription, wsdlOperation); this.operationDescriptions.Add(wsdlOperation, operationDescription); }
internal XmlSerializerMessageContractExporter(WsdlExporter exporter, WsdlContractConversionContext context, OperationDescription operation, IOperationBehavior extension) : base(exporter, context, operation, extension) { }
public DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute) { _dataContractFormatAttribute = dataContractFormatAttribute ?? new DataContractFormatAttribute(); _operation = operation; }
public WsdlNS.Operation GetOperation(OperationDescription operation) { return(this.wsdlOperations[operation]); }
void IOperationBehavior.AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) { }
internal DataContractSerializerOperationBehavior(OperationDescription operation, DataContractFormatAttribute dataContractFormatAttribute, bool builtInOperationBehavior) : this(operation, dataContractFormatAttribute) { _builtInOperationBehavior = builtInOperationBehavior; }
void GenerateEventBasedAsyncSupport(CodeTypeDeclaration type, OperationDescription od, CodeNamespace cns) { var method = FindByName(type, od.Name) ?? FindByName(type, "Begin" + od.Name); var endMethod = method.Name == od.Name ? null : FindByName(type, "End" + od.Name); bool methodAsync = method.Name.StartsWith("Begin", StringComparison.Ordinal); var resultType = endMethod != null ? endMethod.ReturnType : method.ReturnType; var thisExpr = new CodeThisReferenceExpression(); var baseExpr = new CodeBaseReferenceExpression(); var nullExpr = new CodePrimitiveExpression(null); var asyncResultType = new CodeTypeReference(typeof(IAsyncResult)); // OnBeginXxx() implementation var cm = new CodeMemberMethod() { Name = "OnBegin" + od.Name, Attributes = MemberAttributes.Private | MemberAttributes.Final, ReturnType = asyncResultType }; type.Members.Add(cm); AddMethodParam(cm, typeof(object []), "args"); AddMethodParam(cm, typeof(AsyncCallback), "asyncCallback"); AddMethodParam(cm, typeof(object), "userState"); var call = new CodeMethodInvokeExpression( thisExpr, "Begin" + od.Name); for (int idx = 0; idx < method.Parameters.Count - (methodAsync ? 2 : 0); idx++) { var p = method.Parameters [idx]; cm.Statements.Add(new CodeVariableDeclarationStatement(p.Type, p.Name, new CodeCastExpression(p.Type, new CodeArrayIndexerExpression(new CodeArgumentReferenceExpression("args"), new CodePrimitiveExpression(idx))))); call.Parameters.Add(new CodeVariableReferenceExpression(p.Name)); } call.Parameters.Add(new CodeArgumentReferenceExpression("asyncCallback")); call.Parameters.Add(new CodeArgumentReferenceExpression("userState")); cm.Statements.Add(new CodeMethodReturnStatement(call)); // OnEndXxx() implementation cm = new CodeMemberMethod() { Name = "OnEnd" + od.Name, Attributes = MemberAttributes.Private | MemberAttributes.Final, ReturnType = new CodeTypeReference(typeof(object [])) }; type.Members.Add(cm); AddMethodParam(cm, typeof(IAsyncResult), "result"); var outArgRefs = new List <CodeVariableReferenceExpression> (); for (int idx = 0; idx < method.Parameters.Count; idx++) { var p = method.Parameters [idx]; if (p.Direction != FieldDirection.In) { cm.Statements.Add(new CodeVariableDeclarationStatement(p.Type, p.Name)); outArgRefs.Add(new CodeVariableReferenceExpression(p.Name)); // FIXME: should this work? They need "out" or "ref" modifiers. } } call = new CodeMethodInvokeExpression( thisExpr, "End" + od.Name, new CodeArgumentReferenceExpression("result")); call.Parameters.AddRange(outArgRefs.Cast <CodeExpression> ().ToArray()); // questionable var retCreate = new CodeArrayCreateExpression(typeof(object)); if (resultType.BaseType == "System.Void") { cm.Statements.Add(call); } else { cm.Statements.Add(new CodeVariableDeclarationStatement(typeof(object), "__ret", call)); retCreate.Initializers.Add(new CodeVariableReferenceExpression("__ret")); } foreach (var outArgRef in outArgRefs) { retCreate.Initializers.Add(new CodeVariableReferenceExpression(outArgRef.VariableName)); } cm.Statements.Add(new CodeMethodReturnStatement(retCreate)); // OnXxxCompleted() implementation cm = new CodeMemberMethod() { Name = "On" + od.Name + "Completed", Attributes = MemberAttributes.Private | MemberAttributes.Final }; type.Members.Add(cm); AddMethodParam(cm, typeof(object), "state"); string argsname = identifiers.AddUnique(od.Name + "CompletedEventArgs", null); var iaargs = new CodeTypeReference("InvokeAsyncCompletedEventArgs"); // avoid messy System.Type instance for generic nested type :| var iaref = new CodeVariableReferenceExpression("args"); var methodEventArgs = new CodeObjectCreateExpression(new CodeTypeReference(argsname), new CodePropertyReferenceExpression(iaref, "Results"), new CodePropertyReferenceExpression(iaref, "Error"), new CodePropertyReferenceExpression(iaref, "Cancelled"), new CodePropertyReferenceExpression(iaref, "UserState")); cm.Statements.Add(new CodeConditionStatement( new CodeBinaryOperatorExpression( new CodeEventReferenceExpression(thisExpr, od.Name + "Completed"), CodeBinaryOperatorType.IdentityInequality, nullExpr), new CodeVariableDeclarationStatement(iaargs, "args", new CodeCastExpression(iaargs, new CodeArgumentReferenceExpression("state"))), new CodeExpressionStatement(new CodeMethodInvokeExpression(thisExpr, od.Name + "Completed", thisExpr, methodEventArgs)))); // delegate fields type.Members.Add(new CodeMemberField(new CodeTypeReference("BeginOperationDelegate"), "onBegin" + od.Name + "Delegate")); type.Members.Add(new CodeMemberField(new CodeTypeReference("EndOperationDelegate"), "onEnd" + od.Name + "Delegate")); type.Members.Add(new CodeMemberField(new CodeTypeReference(typeof(SendOrPostCallback)), "on" + od.Name + "CompletedDelegate")); // XxxCompletedEventArgs class var argsType = new CodeTypeDeclaration(argsname); argsType.BaseTypes.Add(new CodeTypeReference(typeof(AsyncCompletedEventArgs))); cns.Types.Add(argsType); var argsCtor = new CodeConstructor() { Attributes = MemberAttributes.Public | MemberAttributes.Final }; argsCtor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object []), "results")); argsCtor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(Exception), "error")); argsCtor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(bool), "cancelled")); argsCtor.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "userState")); argsCtor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression("error")); argsCtor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression("cancelled")); argsCtor.BaseConstructorArgs.Add(new CodeArgumentReferenceExpression("userState")); var resultsField = new CodeFieldReferenceExpression(thisExpr, "results"); argsCtor.Statements.Add(new CodeAssignStatement(resultsField, new CodeArgumentReferenceExpression("results"))); argsType.Members.Add(argsCtor); argsType.Members.Add(new CodeMemberField(typeof(object []), "results")); if (resultType.BaseType != "System.Void") { var resultProp = new CodeMemberProperty { Name = "Result", Type = resultType, Attributes = MemberAttributes.Public | MemberAttributes.Final }; resultProp.GetStatements.Add(new CodeMethodReturnStatement(new CodeCastExpression(resultProp.Type, new CodeArrayIndexerExpression(resultsField, new CodePrimitiveExpression(0))))); argsType.Members.Add(resultProp); } // event field var handlerType = new CodeTypeReference(typeof(EventHandler <>)); handlerType.TypeArguments.Add(new CodeTypeReference(argsType.Name)); type.Members.Add(new CodeMemberEvent() { Name = od.Name + "Completed", Type = handlerType, Attributes = MemberAttributes.Public | MemberAttributes.Final }); // XxxAsync() implementations bool hasAsync = false; foreach (int __x in Enumerable.Range(0, 2)) { cm = new CodeMemberMethod(); type.Members.Add(cm); cm.Name = od.Name + "Async"; cm.Attributes = MemberAttributes.Public | MemberAttributes.Final; var inArgs = new List <CodeParameterDeclarationExpression> (); for (int idx = 0; idx < method.Parameters.Count - (methodAsync ? 2 : 0); idx++) { var pd = method.Parameters [idx]; inArgs.Add(pd); cm.Parameters.Add(pd); } // First one is overload without asyncState arg. if (!hasAsync) { call = new CodeMethodInvokeExpression(thisExpr, cm.Name, inArgs.ConvertAll <CodeExpression> (decl => new CodeArgumentReferenceExpression(decl.Name)).ToArray()); call.Parameters.Add(nullExpr); cm.Statements.Add(new CodeExpressionStatement(call)); hasAsync = true; continue; } // Second one is the primary one. cm.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "userState")); // if (onBeginBarOperDelegate == null) onBeginBarOperDelegate = new BeginOperationDelegate (OnBeginBarOper); // if (onEndBarOperDelegate == null) onEndBarOperDelegate = new EndOperationDelegate (OnEndBarOper); // if (onBarOperCompletedDelegate == null) onBarOperCompletedDelegate = new BeginOperationDelegate (OnBarOperCompleted); var beginOperDelegateRef = new CodeFieldReferenceExpression(thisExpr, "onBegin" + od.Name + "Delegate"); var endOperDelegateRef = new CodeFieldReferenceExpression(thisExpr, "onEnd" + od.Name + "Delegate"); var operCompletedDelegateRef = new CodeFieldReferenceExpression(thisExpr, "on" + od.Name + "CompletedDelegate"); var ifstmt = new CodeConditionStatement( new CodeBinaryOperatorExpression(beginOperDelegateRef, CodeBinaryOperatorType.IdentityEquality, nullExpr), new CodeAssignStatement(beginOperDelegateRef, new CodeDelegateCreateExpression(new CodeTypeReference("BeginOperationDelegate"), thisExpr, "OnBegin" + od.Name))); cm.Statements.Add(ifstmt); ifstmt = new CodeConditionStatement( new CodeBinaryOperatorExpression(endOperDelegateRef, CodeBinaryOperatorType.IdentityEquality, nullExpr), new CodeAssignStatement(endOperDelegateRef, new CodeDelegateCreateExpression(new CodeTypeReference("EndOperationDelegate"), thisExpr, "OnEnd" + od.Name))); cm.Statements.Add(ifstmt); ifstmt = new CodeConditionStatement( new CodeBinaryOperatorExpression(operCompletedDelegateRef, CodeBinaryOperatorType.IdentityEquality, nullExpr), new CodeAssignStatement(operCompletedDelegateRef, new CodeDelegateCreateExpression(new CodeTypeReference(typeof(SendOrPostCallback)), thisExpr, "On" + od.Name + "Completed"))); cm.Statements.Add(ifstmt); // InvokeAsync (onBeginBarOperDelegate, inValues, onEndBarOperDelegate, onBarOperCompletedDelegate, userState); inArgs.Add(new CodeParameterDeclarationExpression(typeof(object), "userState")); var args = new List <CodeExpression> (); args.Add(beginOperDelegateRef); args.Add(new CodeArrayCreateExpression(typeof(object), inArgs.ConvertAll <CodeExpression> (decl => new CodeArgumentReferenceExpression(decl.Name)).ToArray())); args.Add(endOperDelegateRef); args.Add(new CodeFieldReferenceExpression(thisExpr, "on" + od.Name + "CompletedDelegate")); args.Add(new CodeArgumentReferenceExpression("userState")); call = new CodeMethodInvokeExpression(baseExpr, "InvokeAsync", args.ToArray()); cm.Statements.Add(new CodeExpressionStatement(call)); } }
public DataContractSerializerOperationBehavior(OperationDescription operation) : this(operation, null) { }
CodeMemberMethod GenerateOperationMethod(CodeTypeDeclaration type, ContractDescription cd, OperationDescription od, bool async, out CodeTypeReference returnType) { CodeMemberMethod cm = new CodeMemberMethod(); if (od.Behaviors.Find <XmlSerializerMappingBehavior> () != null) { cm.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(XmlSerializerFormatAttribute)))); } if (async) { cm.Name = "Begin" + od.Name; } else { cm.Name = od.Name; } if (od.SyncMethod != null) { ExportParameters(cm, od.SyncMethod.GetParameters()); if (async) { AddBeginAsyncArgs(cm); cm.ReturnType = new CodeTypeReference(typeof(IAsyncResult)); } else { cm.ReturnType = new CodeTypeReference(od.SyncMethod.ReturnType); } returnType = new CodeTypeReference(od.SyncMethod.ReturnType); } else { ExportMessages(od.Messages, cm, false); returnType = cm.ReturnType; if (async) { AddBeginAsyncArgs(cm); cm.ReturnType = new CodeTypeReference(typeof(IAsyncResult)); } } // [OperationContract (Action = "...", ReplyAction = "..")] var ad = new CodeAttributeDeclaration(new CodeTypeReference(typeof(OperationContractAttribute))); foreach (MessageDescription md in od.Messages) { if (md.Direction == MessageDirection.Input) { ad.Arguments.Add(new CodeAttributeArgument("Action", new CodePrimitiveExpression(md.Action))); } else { ad.Arguments.Add(new CodeAttributeArgument("ReplyAction", new CodePrimitiveExpression(md.Action))); } } if (async) { ad.Arguments.Add(new CodeAttributeArgument("AsyncPattern", new CodePrimitiveExpression(true))); } cm.CustomAttributes.Add(ad); return(cm); }
void IOperationBehavior.Validate(OperationDescription description) { }
void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy) { }
CodeMemberMethod GenerateImplementationClientMethod(CodeTypeDeclaration type, ContractDescription cd, OperationDescription od, bool async, out CodeTypeReference returnTypeFromMessageContract) { CodeMemberMethod cm = new CodeMemberMethod(); if (async) { cm.Name = "Begin" + od.Name; } else { cm.Name = od.Name; } cm.Attributes = MemberAttributes.Public | MemberAttributes.Final; returnTypeFromMessageContract = null; List <CodeExpression> args = new List <CodeExpression> (); if (od.SyncMethod != null) { ParameterInfo [] pars = od.SyncMethod.GetParameters(); ExportParameters(cm, pars); cm.ReturnType = new CodeTypeReference(od.SyncMethod.ReturnType); int i = 0; foreach (ParameterInfo pi in pars) { args.Add(new CodeArgumentReferenceExpression(pi.Name)); } } else { args.AddRange(ExportMessages(od.Messages, cm, true)); returnTypeFromMessageContract = cm.ReturnType; if (async) { AddBeginAsyncArgs(cm); cm.ReturnType = new CodeTypeReference(typeof(IAsyncResult)); } } if (async) { args.Add(new CodeArgumentReferenceExpression("asyncCallback")); args.Add(new CodeArgumentReferenceExpression("userState")); } CodeExpression call = new CodeMethodInvokeExpression( new CodePropertyReferenceExpression( new CodeBaseReferenceExpression(), "Channel"), cm.Name, args.ToArray()); if (cm.ReturnType.BaseType == "System.Void") { cm.Statements.Add(new CodeExpressionStatement(call)); } else { cm.Statements.Add(new CodeMethodReturnStatement(call)); } return(cm); }
void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch) { }
GetOperationBindingAssertions(OperationDescription operation);