public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { Fx.Assert(operationDescription != null, "OperationDescription cannot be null!"); Fx.Assert(dispatchOperation != null, "DispatchOperation cannot be null!"); if (dispatchOperation.Formatter == null) { return; } this.formatter = dispatchOperation.Formatter; this.faultFormatter = dispatchOperation.FaultFormatter; if (this.receives != null) { foreach (Receive receive in this.receives) { receive.SetFormatter(this.formatter, this.faultFormatter, dispatchOperation.IncludeExceptionDetailInFaults); } } // Remove operation formatter from dispatch runtime dispatchOperation.Formatter = null; dispatchOperation.DeserializeRequest = false; dispatchOperation.SerializeReply = false; }
public CompressionMessageFormatter(MessageCompressor messageCompressor, IDispatchMessageFormatter innerDispatchMessageFormatter, IClientMessageFormatter innerClientMessageFormatter) { this.MessageCompressor = messageCompressor; this.InnerDispatchMessageFormatter = innerDispatchMessageFormatter; this.InnerClientMessageFormatter = innerClientMessageFormatter; }
public FormsPostDispatchMessageFormatter(OperationDescription od, IDispatchMessageFormatter inner, QueryStringConverter queryStringConverter) { this.inner = inner; this.od = od; this.queryStringConverter = queryStringConverter; MessageDescription request = null; foreach (MessageDescription message in od.Messages) { if (message.Direction == MessageDirection.Input) { request = message; break; } } if (request != null && request.MessageType == null) { for (int i = 0; i < request.Body.Parts.Count; ++i) { if (request.Body.Parts[i].Type == typeof(NameValueCollection)) { this.nvcIndex = i; break; } } } }
internal DispatchOperationRuntime(DispatchOperation operation, ImmutableDispatchRuntime parent) { if (operation == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation"); } if (parent == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent"); } if (operation.Invoker == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.RuntimeRequiresInvoker0)); } _disposeParameters = ((operation.AutoDisposeParameters) && (!operation.HasNoDisposableParameters)); _parent = parent; _inspectors = EmptyArray<IParameterInspector>.ToArray(operation.ParameterInspectors); _faultFormatter = operation.FaultFormatter; _deserializeRequest = operation.DeserializeRequest; _serializeReply = operation.SerializeReply; _formatter = operation.Formatter; _invoker = operation.Invoker; _isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled; _action = operation.Action; _name = operation.Name; _replyAction = operation.ReplyAction; _isOneWay = operation.IsOneWay; if (_formatter == null && (_deserializeRequest || _serializeReply)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.DispatchRuntimeRequiresFormatter0, _name))); } }
/// <summary> /// Gets the Dispatch format request. /// </summary> /// <param name="operationDescription">OperationDescription object</param> /// <param name="endpoint">ServiceEndpoint object</param> /// <returns><see cref="DispatchMessageFormatter">DispatchMessageFormatter type</see></returns> protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { /*TODO:This still uses FormPostDispatchFormatter. Need to eliminate/override it completely.*/ IDispatchMessageFormatter inner = base.GetRequestDispatchFormatter(operationDescription, endpoint); return(new EVDispatchFormatter(operationDescription, inner, this.GetQueryStringConverter(operationDescription))); }
public HtmlFormRequestDispatchFormatter(OperationDescription operation, UriTemplate uriTemplate, QueryStringConverter converter, IDispatchMessageFormatter innerFormatter) : base(operation, uriTemplate, converter, innerFormatter) { // This formatter will only support deserializing form post data to a type if: // (1) The type can be converted via the QueryStringConverter or... // (2) The type meets the following requirements: // (A) The type is decorated with the DataContractAttribute // (B) Every public field or property that is decorated with the DataMemberAttribute is of a type that // can be converted by the QueryStringConverter this.canConvertBodyType = this.QueryStringConverter.CanConvert(this.BodyParameterType); if (!this.canConvertBodyType) { if (this.BodyParameterType.GetCustomAttributes(typeof(DataContractAttribute), false).Length == 0) { throw new NotSupportedException( string.Format("Body parameter '{0}' from operation '{1}' is of type '{2}', which is not decorated with a DataContractAttribute. " + "Only body parameter types decorated with the DataContractAttribute are supported.", this.BodyParameterName, operation.Name, this.BodyParameterType)); } // For the body type, we'll need to cache information about each of the public fields/properties // that is decorated with the DataMemberAttribute; we'll store this info in the bodyMembers dictionary // where the member name is the dictionary key bodyMembers = new Dictionary<string, BodyMemberData>(); GetBobyMemberDataForFields(operation.Name); GetBodyMemberDataForProperties(operation.Name); requiredBodyMembers = bodyMembers.Where(p => p.Value.IsRequired == true).Select(p => p.Key).ToArray(); } }
internal void SetFormatter(IDispatchMessageFormatter formatter) { if (this.responseFormatter != null) { this.responseFormatter.Formatter = formatter; } }
public OpenCMISResponseFormatter(IDispatchMessageFormatter innerDispatchFormatter) { if (innerDispatchFormatter == null) throw new ArgumentNullException("innerDispatchFormatter"); this.innerDispatchFormatter = innerDispatchFormatter; }
public OpenCMISResponseFormatter(IDispatchMessageFormatter innerDispatchFormatter) { if (innerDispatchFormatter == null) { throw new ArgumentNullException("innerDispatchFormatter"); } this.innerDispatchFormatter = innerDispatchFormatter; }
public DualModeFormatter(OperationDescription operation, IDispatchMessageFormatter originalFormatter) { this.operation = operation; this.originalFormatter = originalFormatter; this.webMessageEncoder = new WebMessageEncodingBindingElement() .CreateMessageEncoderFactory() .Encoder; this.bufferManager = BufferManager.CreateBufferManager(int.MaxValue, int.MaxValue); }
protected RequestBodyDispatchFormatter(OperationDescription operation, UriTemplate uriTemplate, QueryStringConverter converter, IDispatchMessageFormatter innerFormatter) { // The inner formatter is the default formatter that WCF normally uses. When the request can't be deserialized // by our custom formatter, we'll use the default formatter. this.innerFormatter = innerFormatter; // We'll use the query string converter for both Uri query string parameters and the values of the // form post data this.QueryStringConverter = converter; // Messages[0] is the request message MessagePartDescriptionCollection parts = operation.Messages[0].Body.Parts; // This partsCount includes the Uri parts (both path segment variables and query string variables) // 1 body content part partsCount = parts.Count; ReadOnlyCollection <string> uriPathVariables = uriTemplate.PathSegmentVariableNames; ReadOnlyCollection <string> uriQueryVariables = uriTemplate.QueryValueVariableNames; // For each part of the message, we need to capture it's name, type, and whether it is // a Uri path segment variable, a Uri query string variable or the body content operationParameterInfo = new OperationParameterInfo[partsCount]; for (int x = 0; x < partsCount; x++) { string name = parts[x].Name; Type type = parts[x].Type; // We'll assume this part is the message body, but then check if there are // uri variables that match the name OperationParameterKind kind = OperationParameterKind.MessageBody; bool canConvert = false; CaseInsensitiveEqualityComparer <string> comparer = new CaseInsensitiveEqualityComparer <string>(); if (uriPathVariables.Contains(name, comparer)) { kind = OperationParameterKind.UriPathVariable; } else if (uriQueryVariables.Contains(name, comparer)) { canConvert = converter.CanConvert(type); kind = OperationParameterKind.UriQueryVariable; } else { // If we reached here, then this part really is the message body part. // We'll store the name and type in the class properties so that derived // types have access to this information this.BodyParameterName = name; this.BodyParameterType = type; } operationParameterInfo[x] = new OperationParameterInfo(kind, type, name, canConvert); } }
/// <summary> /// Modifies the request dispatch formatter to read query paramters from the message body. /// </summary> /// <param name="operationDescription">The specified operation description.</param> /// <param name="endpoint">The specified endpoint.</param> /// <returns>The request dispatch formatter for the specified operation description and endpoint.</returns> protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { IDispatchMessageFormatter formatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); IQueryOperationSettings querySettings = operationDescription.Behaviors.Find <IQueryOperationSettings>(); if (querySettings != null) { formatter = new WebHttpQueryDispatchMessageFormatter(formatter, querySettings.HasSideEffects); } return(formatter); }
public WcfDispatchMessageFormatter(IDispatchMessageFormatter innerDispatchFormatter, WcfMessageEncodingContext context, IWcfMessageEncodingController controller) { if (innerDispatchFormatter == null) { throw new ArgumentNullException("innerDispatchFormatter"); } _innerDispatchFormatter = innerDispatchFormatter; _context = context; _controller = controller; }
protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { // This is the default formatter for the operation, which we may wrap with our custom formatter IDispatchMessageFormatter formatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); // Messages[0] is the request message int partsCount = operationDescription.Messages[0].Body.Parts.Count; // If the message doesn't have any parts, then it can't have any body content so a form post isn't applicable if (partsCount == 0) { return(formatter); } //For [WebInvoke] operations with body content, we want to wrap the base formatter with our HtmlFormRequestDispatchFormatter WebInvokeAttribute webInvoke = operationDescription.Behaviors.Find <WebInvokeAttribute>(); if (webInvoke != null) { if (webInvoke.BodyStyle == WebMessageBodyStyle.Wrapped) { throw new InvalidOperationException("The FormProcessingBehavior does not support wrapped requests or responses."); } // We need to determine the parts of the message that are associated with the Uri and those that are associated // with the body content of the request. To do this, we need to get the Uri template for the operation and determine // how many parameters it has UriTemplate uriTemplate = null; int bodyPartsCount = partsCount; if (!string.IsNullOrEmpty(webInvoke.UriTemplate)) { uriTemplate = new UriTemplate(webInvoke.UriTemplate); // The number of message parts for the request body will be the equal to the total parts for the message minus // the total number of UriTemplate variables bodyPartsCount = partsCount - (uriTemplate.PathSegmentVariableNames.Count + uriTemplate.QueryValueVariableNames.Count); } else { uriTemplate = new UriTemplate(string.Empty); } // Since we've disallowed wrapped message bodies, we can be sure that the message will only have // 0 or 1 message parts that are associated with the body of the request. if (bodyPartsCount == 1) { QueryStringConverter converter = this.GetQueryStringConverter(operationDescription); formatter = new HtmlFormRequestDispatchFormatter(operationDescription, uriTemplate, converter, formatter); } } return(formatter); }
public DemultiplexingDispatchMessageFormatter(IDictionary <WebContentFormat, IDispatchMessageFormatter> formatters, IDispatchMessageFormatter defaultFormatter) { if (formatters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("formatters"); } this.formatters = new Dictionary <WebContentFormat, IDispatchMessageFormatter>(); foreach (WebContentFormat key in formatters.Keys) { this.formatters.Add(key, formatters[key]); } this.defaultFormatter = defaultFormatter; }
public ContentTypeSettingDispatchMessageFormatter(string outgoingContentType, IDispatchMessageFormatter innerFormatter) { if (outgoingContentType == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("outgoingContentType"); } if (innerFormatter == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("innerFormatter"); } this.outgoingContentType = outgoingContentType; this.innerFormatter = innerFormatter; }
public DemultiplexingDispatchMessageFormatter(IDictionary<WebContentFormat, IDispatchMessageFormatter> formatters, IDispatchMessageFormatter defaultFormatter) { if (formatters == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("formatters"); } this.formatters = new Dictionary<WebContentFormat, IDispatchMessageFormatter>(); foreach (WebContentFormat key in formatters.Keys) { this.formatters.Add(key, formatters[key]); } this.defaultFormatter = defaultFormatter; }
/// <summary> /// for server /// </summary> /// <param name="operationName"></param> /// <param name="parameterInfos"></param> /// <param name="innerDispatchFormatter"></param> public BinaryFormatterAdapter( string operationName, ParameterInfo[] parameterInfos, IDispatchMessageFormatter innerDispatchFormatter ) { if (operationName == null) throw new ArgumentNullException("operationName"); if (parameterInfos == null) throw new ArgumentNullException("parameterInfos"); if (innerDispatchFormatter == null) throw new ArgumentNullException("innerDispatchFormatter"); this._innerDispatchFormatter = innerDispatchFormatter; this._operationName = operationName; this._parameterInfos = parameterInfos; }
public WebDispatchFormatter( WebFormatterFactory formatterFactory, OperationDescription operationDescription, IDispatchMessageFormatter originalFormatter, FormatterDirection direction) { _formatterFactory = formatterFactory; _requestParameters = operationDescription.GetRequestMessageParts(); _responseType = operationDescription.GetResponseType(); _direction = direction; if (direction != FormatterDirection.Both) _originalFormatter = originalFormatter; }
public UriTemplateDispatchFormatter(OperationDescription operationDescription, IDispatchMessageFormatter inner, QueryStringConverter qsc, string contractName, Uri baseAddress) { this.inner = inner; this.qsc = qsc; this.baseAddress = baseAddress; this.operationName = operationDescription.Name; UriTemplateClientFormatter.Populate(out this.pathMapping, out this.queryMapping, out this.totalNumUTVars, out this.uriTemplate, operationDescription, qsc, contractName); }
/// <summary> /// 获取Server端处理响应的格式化器 /// </summary> /// <param name="operationDescription"></param> /// <param name="endpoint"></param> /// <returns></returns> protected override IDispatchMessageFormatter GetReplyDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { IDispatchMessageFormatter formatter = null; if (IsOperationReturnVoid(operationDescription) || operationDescription.Behaviors.Find <WfJsonFormatterAttribute>() == null) { formatter = base.GetReplyDispatchFormatter(operationDescription, endpoint); } else { formatter = formatter = CreateDispatchFormatter(operationDescription, endpoint); } return(formatter); }
public FormDataDispatchFormatter(OperationDescription operation, IDispatchMessageFormatter originalFormatter) { var inputMessageBodyParts = operation.Messages[0].Body.Parts; this.parameterNames = new Dictionary <string, int>(); for (int i = 0; i < inputMessageBodyParts.Count; i++) { if (inputMessageBodyParts[i].Type == typeof(string)) { // For now, only support string parameters; others will be ignored this.parameterNames.Add(inputMessageBodyParts[i].Name, i); } } this.originalFormatter = originalFormatter; }
public static IDispatchMessageFormatter CreateXmlAndJsonDispatchFormatter(OperationDescription operation, Type type, bool isRequestFormatter, UnwrappedTypesXmlSerializerManager xmlSerializerManager, string callbackParameterName) { IDispatchMessageFormatter xmlFormatter = CreateDispatchFormatter(operation, type, isRequestFormatter, false, xmlSerializerManager, null); if (!WebHttpBehavior.SupportsJsonFormat(operation)) { return(xmlFormatter); } IDispatchMessageFormatter jsonFormatter = CreateDispatchFormatter(operation, type, isRequestFormatter, true, xmlSerializerManager, callbackParameterName); Dictionary <WebContentFormat, IDispatchMessageFormatter> map = new Dictionary <WebContentFormat, IDispatchMessageFormatter>(); map.Add(WebContentFormat.Xml, xmlFormatter); map.Add(WebContentFormat.Json, jsonFormatter); return(new DemultiplexingDispatchMessageFormatter(map, xmlFormatter)); }
public WebDispatchFormatter( WebFormatterFactory formatterFactory, OperationDescription operationDescription, IDispatchMessageFormatter originalFormatter, FormatterDirection direction) { _formatterFactory = formatterFactory; _requestParameters = operationDescription.GetRequestMessageParts(); _responseType = operationDescription.GetResponseType(); _direction = direction; if (direction != FormatterDirection.Both) { _originalFormatter = originalFormatter; } }
public QueryStringFormatter(string operationName, ParameterInfo[] parameterInfos, IDispatchMessageFormatter innerDispatchFormatter) { if (operationName == null) throw new ArgumentNullException("operationName"); if (parameterInfos == null) throw new ArgumentNullException("parameterInfos"); if (innerDispatchFormatter == null) throw new ArgumentNullException("innerDispatchFormatter"); QueryStringFormatter.ValidateSupportedType(parameterInfos); this.innerDispatchFormatter = innerDispatchFormatter; this.operationName = operationName; this.parameterInfos = parameterInfos; }
/// <summary> /// </summary> /// <param name="operationDescription"></param> /// <param name="endpoint"></param> /// <returns></returns> protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { IDispatchMessageFormatter formatter = null; //formatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); if (this.IsGetOperation(operationDescription)) { var flags = BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod; var method = typeof(WebHttpBehavior).GetMethod("GetRequestDispatchFormatter", flags); return(method.Invoke(this.basicImplementor, new object[] { operationDescription, endpoint }) as IDispatchMessageFormatter); } else { formatter = new NissingDispatchMessageFormatter(); } return(formatter); }
IHttpHandler CreateHandler(Type serviceType) { MessageEncoderFactory encoder = ComponentBuilder.GetMessageEncoderFactory(); WcfHandler handler = new WcfHandler(serviceType, encoder); Type interfaceType = serviceType.GetInterfaces()[0]; ContractDescription contract = ContractDescription.GetContract(interfaceType); foreach (var item in contract.Operations) { IDispatchMessageFormatter formatter = (IDispatchMessageFormatter)ComponentBuilder.GetMessageFormatter(item, false); IOperationInvoker invoker = ComponentBuilder.GetOperationInvoker(item.SyncMethod); handler.DispatchMessageFormatters.Add(item.Messages[0].Action, formatter); handler.OperationInvokers.Add(item.Messages[0].Action, invoker); handler.Methods.Add(item.Messages[0].Action, item.SyncMethod); } return(handler); }
protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { bool isRequestWrapped = this.IsRequestWrapped(operationDescription.Behaviors.Find <WebInvokeAttribute>()); IDispatchMessageFormatter originalFormatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); if (isRequestWrapped) { return(new MyFormUrlEncodedAwareFormatter( operationDescription, originalFormatter, this.GetQueryStringConverter(operationDescription))); } else { return(originalFormatter); } }
public void ApplyDispatchBehavior(OperationDescription operationDescription, DispatchOperation dispatchOperation) { if (dispatchOperation.Formatter != null) { this.formatter = dispatchOperation.Formatter; this.faultFormatter = dispatchOperation.FaultFormatter; if (this.receives != null) { foreach (Receive receive in this.receives) { receive.SetFormatter(this.formatter, this.faultFormatter, dispatchOperation.IncludeExceptionDetailInFaults); } } dispatchOperation.Formatter = null; dispatchOperation.DeserializeRequest = false; dispatchOperation.SerializeReply = false; } }
internal void SetFormatter(IDispatchMessageFormatter formatter, IDispatchFaultFormatter faultFormatter, bool includeExceptionDetailInFaults) { this.requestFormatter.Formatter = formatter; if (this.followingReplies != null) { for (int i = 0; i < this.followingReplies.Count; i++) { this.followingReplies[i].SetFormatter(formatter); } } if (this.followingFaults != null) { for (int j = 0; j < this.followingFaults.Count; j++) { this.followingFaults[j].SetFaultFormatter(faultFormatter, includeExceptionDetailInFaults); } } }
public void OnDeserializeRequestExecutesRequestPipeline() { SHttpOperationDescription operation = new SHttpOperationDescription() { CallBase = true, ReturnValue = HttpParameter.ResponseMessage }; IEnumerable <HttpOperationHandler> emptyHandlers = Enumerable.Empty <HttpOperationHandler>(); OperationHandlerPipeline pipeline = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation); MOperationHandlerPipeline molePipeline = new MOperationHandlerPipeline(pipeline); molePipeline.BehaveAsDefaultValue(); MOperationHandlerPipelineContext moleContext = new MOperationHandlerPipelineContext(); HttpRequestMessage setRequest = null; object[] setValues = null; OperationHandlerPipelineContext setContext = null; molePipeline.ExecuteRequestPipelineHttpRequestMessageObjectArray = (request, values) => { setRequest = request; setValues = values; return(setContext = moleContext); }; OperationHandlerFormatter formatter = new OperationHandlerFormatter(molePipeline); IDispatchMessageFormatter dispatchMessageFormatter = (IDispatchMessageFormatter)formatter; Uri uri = new Uri("http://somehost/Fred"); HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, uri); httpRequest.Content = new StringContent(""); Message message = httpRequest.ToMessage(); object[] parameters = new object[0]; dispatchMessageFormatter.DeserializeRequest(message, parameters); HttpAssert.AreEqual(httpRequest, setRequest); Assert.IsNotNull(setValues, "Input values were not passed to the pipeline."); Assert.AreEqual(0, ((object[])setValues).Length, "Incorrect number of values."); Assert.IsNotNull(setContext, "Context was not set."); }
/// <summary> /// Initializes a new instance of the EVDispatchFormatter class /// </summary> /// <param name="od">OperationDescription object</param> /// <param name="inner">DispatchMessageFormatter object</param> /// <param name="queryStringConverter">QueryStringConverter object</param> public EVDispatchFormatter(OperationDescription od, IDispatchMessageFormatter inner, QueryStringConverter queryStringConverter) { this.inner = inner; this.od = od; this.queryStringConverter = queryStringConverter; MessageDescription request = od.Messages.FirstOrDefault(message => message.Direction == MessageDirection.Input); if (request != null && request.MessageType == null) { for (int i = 0; i < request.Body.Parts.Count; ++i) { if (request.Body.Parts[i].Type == typeof(NameValueCollection)) { this.nvcIndex = i; break; } } } }
protected IHttpHandler CreateHttpHandler(Type serviceType) { MessageEncoderFactory encoderFactory = ComponentBuilder.GetMessageEncoderFactory(MessageVersion.Default, Encoding.UTF8); WcfHandler handler = new WcfHandler(serviceType, encoderFactory); Type interfaceType = serviceType.GetInterfaces()[0]; ContractDescription contract = ContractDescription.GetContract(interfaceType); foreach (OperationDescription operation in contract.Operations) { IDispatchMessageFormatter messageFormatter = (IDispatchMessageFormatter)ComponentBuilder.GetFormatter(operation, false); handler.MessageFormatters.Add(operation.Messages[0].Action, messageFormatter); IOperationInvoker operationInvoker = ComponentBuilder.GetOperationInvoker(operation.SyncMethod); handler.OperationInvokers.Add(operation.Messages[0].Action, operationInvoker); handler.Methods.Add(operation.Messages[0].Action, operation.SyncMethod); } return(handler); }
public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { DomainServiceDescription description = DomainServiceDescription.GetDescription(endpoint.Contract.ContractType); ServiceMetadataGenerator.GenerateEntitiesMetadataJsonMap(description); foreach (OperationDescription od in endpoint.Contract.Operations) { foreach (IOperationBehavior behavior in od.Behaviors) { Type behaviorType = behavior.GetType(); if (behaviorType.IsGenericType && behaviorType.GetGenericTypeDefinition().Equals(typeof(QueryOperationBehavior <>))) { IDispatchMessageFormatter innerFormatter = endpointDispatcher.DispatchRuntime.Operations[od.Name].Formatter; endpointDispatcher.DispatchRuntime.Operations[od.Name].Formatter = new ServiceMetadataQueryOperationMessageFormatter(innerFormatter, DomainOperationType.Query, description.GetQueryMethod(od.Name).ReturnType); } } } }
/// <summary> /// 获取Server端处理请求的格式化器 /// </summary> /// <param name="operationDescription"></param> /// <param name="endpoint"></param> /// <returns></returns> protected override IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { IDispatchMessageFormatter formatter = null; if (this.IsWebGetOperation(operationDescription)) { formatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); } else if (operationDescription.Behaviors.Find <WfJsonFormatterAttribute>() == null) { formatter = base.GetRequestDispatchFormatter(operationDescription, endpoint); } else { formatter = CreateDispatchFormatter(operationDescription, endpoint); } return(formatter); }
public void OnSerializeReplyExecutesResponsePipeline() { SHttpOperationDescription operation = new SHttpOperationDescription() { CallBase = true, ReturnValue = HttpParameter.ResponseMessage }; IEnumerable <HttpOperationHandler> emptyHandlers = Enumerable.Empty <HttpOperationHandler>(); OperationHandlerPipeline pipeline = new OperationHandlerPipeline(emptyHandlers, emptyHandlers, operation); MOperationHandlerPipeline molePipeline = new MOperationHandlerPipeline(pipeline); molePipeline.BehaveAsDefaultValue(); MOperationHandlerPipelineContext moleContext = new MOperationHandlerPipelineContext(); HttpResponseMessage response = new HttpResponseMessage(); OperationHandlerPipelineContext setContext = null; object[] setValues = null; object setResult = null; molePipeline.ExecuteResponsePipelineOperationHandlerPipelineContextObjectArrayObject = (context, values, result) => { setContext = context; setValues = values; setResult = result; return(response); }; OperationHandlerFormatter formatter = new OperationHandlerFormatter(molePipeline); IDispatchMessageFormatter dispatchMessageFormatter = (IDispatchMessageFormatter)formatter; object[] parameters = new object[] { 1, "text" }; Message message = dispatchMessageFormatter.SerializeReply(MessageVersion.None, parameters, "theResult"); Assert.IsNotNull(setValues, "Input values were not passed to the pipeline."); CollectionAssert.AreEqual(new List <object>(parameters), new List <object>(setValues), "Parameters were not passed correctly."); Assert.AreEqual("theResult", setResult, "Result was not passed correctly."); Assert.IsNotNull(setContext, "Context was not set."); }
protected override IDispatchMessageFormatter GetReplyDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { WebGetAttribute webGetAttribute = operationDescription.Behaviors.Find <WebGetAttribute>(); WebInvokeAttribute webInvokeAttr = operationDescription.Behaviors.Find <WebInvokeAttribute>(); DynamicResponseTypeAttribute mapAcceptedContentTypeToResponseEncodingAttribute = operationDescription.Behaviors.Find <DynamicResponseTypeAttribute>(); if (webGetAttribute != null && mapAcceptedContentTypeToResponseEncodingAttribute != null) { // We need two formatters, since we don't know what type we will need until runtime webGetAttribute.ResponseFormat = WebMessageFormat.Json; IDispatchMessageFormatter jsonDispatchMessageFormatter = base.GetReplyDispatchFormatter(operationDescription, endpoint); webGetAttribute.ResponseFormat = WebMessageFormat.Xml; IDispatchMessageFormatter xmlDispatchMessageFormatter = base.GetReplyDispatchFormatter(operationDescription, endpoint); return(new DynamicFormatter() { jsonDispatchMessageFormatter = jsonDispatchMessageFormatter, xmlDispatchMessageFormatter = xmlDispatchMessageFormatter }); } else if (webInvokeAttr != null && mapAcceptedContentTypeToResponseEncodingAttribute != null) { // We need two formatters, since we don't know what type we will need until runtime webInvokeAttr.ResponseFormat = WebMessageFormat.Json; IDispatchMessageFormatter jsonDispatchMessageFormatter = base.GetReplyDispatchFormatter(operationDescription, endpoint); webInvokeAttr.ResponseFormat = WebMessageFormat.Xml; IDispatchMessageFormatter xmlDispatchMessageFormatter = base.GetReplyDispatchFormatter(operationDescription, endpoint); return(new DynamicFormatter() { jsonDispatchMessageFormatter = jsonDispatchMessageFormatter, xmlDispatchMessageFormatter = xmlDispatchMessageFormatter }); } return(base.GetReplyDispatchFormatter(operationDescription, endpoint)); }
public CustomMessageFormatter(IDispatchMessageFormatter innerDispatchFormatter) { InnerDispatchFormatter = innerDispatchFormatter; }
public MyDispatchMessageFormatter(IDispatchMessageFormatter inner) { this.inner = inner; }
public CorsFormatter(IDispatchMessageFormatter formatter) { _originalFormatter = formatter; }
internal void SetFormatter(IDispatchMessageFormatter formatter, IDispatchFaultFormatter faultFormatter, bool includeExceptionDetailInFaults) { if (this.requestFormatter != null) { this.requestFormatter.Formatter = formatter; } if (this.followingReplies != null) { for (int i = 0; i < this.followingReplies.Count; i++) { this.followingReplies[i].SetFormatter(formatter); } } if (this.followingFaults != null) { for (int i = 0; i < this.followingFaults.Count; i++) { this.followingFaults[i].SetFaultFormatter(faultFormatter, includeExceptionDetailInFaults); } } }
internal DispatchOperationRuntime(DispatchOperation operation, ImmutableDispatchRuntime parent) { if (operation == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operation"); } if (parent == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("parent"); } if (operation.Invoker == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.RuntimeRequiresInvoker0))); } this.disposeParameters = ((operation.AutoDisposeParameters) && (!operation.HasNoDisposableParameters)); this.parent = parent; this.callContextInitializers = EmptyArray<ICallContextInitializer>.ToArray(operation.CallContextInitializers); this.inspectors = EmptyArray<IParameterInspector>.ToArray(operation.ParameterInspectors); this.faultFormatter = operation.FaultFormatter; this.impersonation = operation.Impersonation; this.deserializeRequest = operation.DeserializeRequest; this.serializeReply = operation.SerializeReply; this.formatter = operation.Formatter; this.invoker = operation.Invoker; try { this.isSynchronous = operation.Invoker.IsSynchronous; } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperCallback(e); } this.isTerminating = operation.IsTerminating; this.isSessionOpenNotificationEnabled = operation.IsSessionOpenNotificationEnabled; this.action = operation.Action; this.name = operation.Name; this.releaseInstanceAfterCall = operation.ReleaseInstanceAfterCall; this.releaseInstanceBeforeCall = operation.ReleaseInstanceBeforeCall; this.replyAction = operation.ReplyAction; this.isOneWay = operation.IsOneWay; this.transactionAutoComplete = operation.TransactionAutoComplete; this.transactionRequired = operation.TransactionRequired; this.receiveContextAcknowledgementMode = operation.ReceiveContextAcknowledgementMode; this.bufferedReceiveEnabled = operation.BufferedReceiveEnabled; this.isInsideTransactedReceiveScope = operation.IsInsideTransactedReceiveScope; if (this.formatter == null && (deserializeRequest || serializeReply)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.DispatchRuntimeRequiresFormatter0, this.name))); } if ((operation.Parent.InstanceProvider == null) && (operation.Parent.Type != null)) { SyncMethodInvoker sync = this.invoker as SyncMethodInvoker; if (sync != null) { this.ValidateInstanceType(operation.Parent.Type, sync.Method); } AsyncMethodInvoker async = this.invoker as AsyncMethodInvoker; if (async != null) { this.ValidateInstanceType(operation.Parent.Type, async.BeginMethod); this.ValidateInstanceType(operation.Parent.Type, async.EndMethod); } TaskMethodInvoker task = this.invoker as TaskMethodInvoker; if (task != null) { this.ValidateInstanceType(operation.Parent.Type, task.TaskMethod); } } }
public CustomMessageFormatter(IDispatchMessageFormatter oldFormatter) { this.oldFormatter = oldFormatter; }
public TraceMessageSizeFormatter( DispatchOperation dispatchOperation) { this.dispatchOperation = dispatchOperation; this.innerFormatter = dispatchOperation.Formatter; }
public JsonFormatter(IDispatchMessageFormatter original, OperationDescription operationDescription) { this.original = original; this.operationDescription = operationDescription; }
public ServiceMetadataQueryOperationMessageFormatter(IDispatchMessageFormatter innerFormatter, DomainOperationType operationType, Type entityType) { this.innerFormatter = innerFormatter; this.operationType = operationType; this.entityType = TypeUtility.GetElementType(entityType); }
public WebHttpQueryDispatchMessageFormatter(IDispatchMessageFormatter innerDispatchMessageFormatter, bool queryHasSideEffects) { this._innerDispatchMessageFormatter = innerDispatchMessageFormatter; this._queryHasSideEffects = queryHasSideEffects; }
public NullifyEmptyElementsFormatter(IDispatchMessageFormatter innerFormatter) { // Save the original formatter _innerFormatter = innerFormatter; }
public MessageFormatter(IDispatchMessageFormatter dispatchMessageFormatter) { this.originalFormatter = dispatchMessageFormatter; }
public DispatchPairFormatter (IDispatchMessageFormatter request, IDispatchMessageFormatter reply) { this.request = request; this.reply = reply; }
public CompositeDispatchFormatter(IDispatchMessageFormatter request, IDispatchMessageFormatter reply) { this.request = request; this.reply = reply; }