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); } }
void UpdateOperationParameters() { WorkflowServiceOperationListItem workflowOperationListItem = this.Item as WorkflowServiceOperationListItem; Fx.Assert(workflowOperationListItem != null, "UpdateOperation should only be called on workflowOperations"); workflowOperationListItem.Operation.Parameters.Clear(); int paramPosition = 0; foreach (DataGridViewRow row in this.parametersGrid.Rows) { string name = row.Cells[this.nameColumn.Index].Value as string; object typeCell = row.Cells[this.typeColumn.Index].Value; string direction = row.Cells[this.directionColumn.Index].Value as string; if (string.IsNullOrEmpty(name) || name.Equals(this.ParameterTemplateRowName)) { continue; } if (typeCell == null) { continue; } if (string.IsNullOrEmpty(direction)) { continue; } OperationParameterInfo operationParameterInfo = new OperationParameterInfo(name); operationParameterInfo.ParameterType = typeCell as Type; if (direction.Equals(SR2.GetString(SR2.ParameterDirectionIn))) { operationParameterInfo.Attributes |= ParameterAttributes.In; } if (direction.Equals(SR2.GetString(SR2.ParameterDirectionOut))) { operationParameterInfo.Attributes |= ParameterAttributes.Out; } if (direction.Equals(SR2.GetString(SR2.ParameterDirectionRef))) { operationParameterInfo.Attributes |= ParameterAttributes.In; operationParameterInfo.Attributes |= ParameterAttributes.Out; } if (name.Equals(SR2.GetString(SR2.ReturnValueString))) { operationParameterInfo.Attributes |= ParameterAttributes.Retval; operationParameterInfo.Position = -1; } else { operationParameterInfo.Position = paramPosition; paramPosition++; } workflowOperationListItem.Operation.Parameters.Add(operationParameterInfo); } UpdateImplementingActivities(); }
void container4() { //OperationInfo.Parameters //<snippet4> ReceiveActivity receive = new ReceiveActivity(); OperationInfo info = new OperationInfo(); info.Name = "Echo"; OperationParameterInfo parameterInfo = new OperationParameterInfo(); parameterInfo.Attributes = ((System.Reflection.ParameterAttributes)((System.Reflection.ParameterAttributes.Out | System.Reflection.ParameterAttributes.Retval))); parameterInfo.Name = "(ReturnValue)"; parameterInfo.ParameterType = typeof(string); parameterInfo.Position = -1; info.Parameters.Add(parameterInfo); receive.ServiceOperationInfo = info; //</snippet4> }