internal static void HideRequestUriTemplateParameters(OperationDescription operationDescription, UriTemplateDispatchFormatter throwAway, Effect effect) { HideRequestUriTemplateParameters(operationDescription, throwAway.pathMapping, throwAway.queryMapping, effect); }
static bool IsRawContentMapperCompatibleDispatchOperation(OperationDescription operation, ref int numStreamOperations) { // An operation is raw encoder compatible on the dispatch side iff the request body is a Stream or void // The response is driven by the format property on the message and not by the content type UriTemplateDispatchFormatter throwAway = new UriTemplateDispatchFormatter(operation, null, new QueryStringConverter(), operation.DeclaringContract.Name, new Uri("http://localhost")); int numUriVariables = throwAway.pathMapping.Count + throwAway.queryMapping.Count; bool isRequestCompatible = false; if (numUriVariables > 0) { // we need the local variable tmp because ref parameters are not allowed to be passed into // anonymous methods by the compiler. int tmp = 0; WebHttpBehavior.HideRequestUriTemplateParameters(operation, throwAway, delegate() { isRequestCompatible = IsRequestStreamOrVoid(operation, ref tmp); }); numStreamOperations += tmp; } else { isRequestCompatible = IsRequestStreamOrVoid(operation, ref numStreamOperations); } return isRequestCompatible; }
protected virtual IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint) { IDispatchMessageFormatter result = null; // get some validation errors by creating "throwAway" formatter UriTemplateDispatchFormatter throwAway = new UriTemplateDispatchFormatter(operationDescription, null, GetQueryStringConverter(operationDescription), endpoint.Contract.Name, endpoint.Address.Uri); int numUriVariables = throwAway.pathMapping.Count + throwAway.queryMapping.Count; HideReplyMessage(operationDescription, delegate() { WebMessageBodyStyle style = GetBodyStyle(operationDescription); Effect doBodyFormatter = delegate() { if (numUriVariables != 0) { EnsureNotUntypedMessageNorMessageContract(operationDescription); } // get body formatter ValidateBodyParameters(operationDescription, true); Type type; if (TryGetStreamParameterType(operationDescription.Messages[0], operationDescription, true, out type)) { result = new HttpStreamFormatter(operationDescription); } else { Type parameterType; if (UseBareRequestFormatter(style, operationDescription, out parameterType)) { result = SingleBodyParameterMessageFormatter.CreateXmlAndJsonDispatchFormatter(operationDescription, parameterType, true, this.xmlSerializerManager, this.JavascriptCallbackParameterName); } else { result = GetDefaultXmlAndJsonDispatchFormatter(operationDescription, !IsBareRequest(style)); } } }; if (numUriVariables == 0) { if (IsUntypedMessage(operationDescription.Messages[0])) { ValidateBodyParameters(operationDescription, true); result = new MessagePassthroughFormatter(); } else if (IsTypedMessage(operationDescription.Messages[0])) { ValidateBodyParameters(operationDescription, true); result = GetDefaultXmlAndJsonDispatchFormatter(operationDescription, !IsBareRequest(style)); } else { doBodyFormatter(); } } else { HideRequestUriTemplateParameters(operationDescription, throwAway, delegate() { CloneMessageDescriptionsBeforeActing(operationDescription, delegate() { doBodyFormatter(); }); }); } result = new UriTemplateDispatchFormatter(operationDescription, result, GetQueryStringConverter(operationDescription), endpoint.Contract.Name, endpoint.Address.Uri); }); return result; }