/// <summary> /// Create message reader settings for consuming responses. /// </summary> /// <param name="entryXmlCustomizer">Optional XML entry customization callback to be used.</param> /// <returns>Newly created message reader settings.</returns> internal ODataMessageReaderSettings CreateSettings(Func <ODataEntry, XmlReader, Uri, XmlReader> entryXmlCustomizer) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); if (!this.responseInfo.ResponsePipeline.HasAtomReadingEntityHandlers) { entryXmlCustomizer = null; } Func <IEdmType, string, IEdmType> resolveWireTypeName = this.responseInfo.TypeResolver.ResolveWireTypeName; if (this.responseInfo.Context.Format.ServiceModel != null) { resolveWireTypeName = null; } settings.EnableWcfDataServicesClientBehavior( resolveWireTypeName, this.responseInfo.DataNamespace, UriUtil.UriToString(this.responseInfo.TypeScheme), entryXmlCustomizer); settings.BaseUri = this.responseInfo.BaseUriResolver.BaseUriOrNull; settings.MaxProtocolVersion = CommonUtil.ConvertToODataVersion(this.responseInfo.MaxProtocolVersion); settings.UndeclaredPropertyBehaviorKinds = this.responseInfo.UndeclaredPropertyBehaviorKinds | ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty; CommonUtil.SetDefaultMessageQuotas(settings.MessageQuotas); this.responseInfo.ResponsePipeline.ExecuteReaderSettingsConfiguration(settings); return(settings); }
internal static ODataMessageReaderSettings CreateODataMessageReaderSettings(ResponseInfo responseInfo, Func <ODataEntry, XmlReader, Uri, XmlReader> entryXmlCustomizer, bool projectionQuery) { ODataMessageReaderSettings settings = new ODataMessageReaderSettings(); responseInfo.TypeResolver = new TypeResolver(responseInfo, projectionQuery); settings.EnableWcfDataServicesClientBehavior(new Func <IEdmType, string, IEdmType>(responseInfo.TypeResolver.ResolveWireTypeName), responseInfo.DataNamespace, CommonUtil.UriToString(responseInfo.TypeScheme), entryXmlCustomizer); settings.BaseUri = (responseInfo.BaseUriResolver.GetRawBaseUriValue() != null) ? responseInfo.BaseUriResolver.GetBaseUriWithSlash() : null; settings.UndeclaredPropertyBehaviorKinds = ODataUndeclaredPropertyBehaviorKinds.ReportUndeclaredLinkProperty; settings.MaxProtocolVersion = CommonUtil.ConvertToODataVersion(responseInfo.MaxProtocolVersion); if (responseInfo.IgnoreMissingProperties) { settings.UndeclaredPropertyBehaviorKinds |= ODataUndeclaredPropertyBehaviorKinds.IgnoreUndeclaredValueProperty; } settings.MessageQuotas.MaxEntityPropertyMappingsPerType = 0x7fffffff; settings.MessageQuotas.MaxNestingDepth = 0x7fffffff; settings.MessageQuotas.MaxOperationsPerChangeset = 0x7fffffff; settings.MessageQuotas.MaxPartsPerBatch = 0x7fffffff; settings.MessageQuotas.MaxReceivedMessageSize = 0x7fffffffffffffffL; return(settings); }
private string ConvertToEscapedUriValue(string paramName, object value) { object obj2 = null; string str; bool flag = false; if (value == null) { flag = true; } else if (value.GetType() == typeof(ODataUriNullValue)) { obj2 = value; flag = true; } else { ClientTypeAnnotation annotation3; ClientEdmModel model = ClientEdmModel.GetModel(this.requestInfo.MaxProtocolVersion); IEdmType orCreateEdmType = model.GetOrCreateEdmType(value.GetType()); switch (orCreateEdmType.TypeKind) { case EdmTypeKind.Primitive: obj2 = value; flag = true; goto Label_0155; case EdmTypeKind.Complex: { ClientTypeAnnotation clientTypeAnnotation = model.GetClientTypeAnnotation(orCreateEdmType); obj2 = this.CreateODataComplexValue(clientTypeAnnotation.ElementType, value, null, false, null); SerializationTypeNameAnnotation annotation = ((ODataComplexValue)obj2).GetAnnotation <SerializationTypeNameAnnotation>(); if ((annotation == null) || string.IsNullOrEmpty(annotation.TypeName)) { throw System.Data.Services.Client.Error.InvalidOperation(System.Data.Services.Client.Strings.DataServiceException_GeneralError); } goto Label_0155; } case EdmTypeKind.Collection: { IEdmCollectionType type2 = orCreateEdmType as IEdmCollectionType; IEdmTypeReference elementType = type2.ElementType; annotation3 = model.GetClientTypeAnnotation(elementType.Definition); switch (annotation3.EdmType.TypeKind) { case EdmTypeKind.Primitive: case EdmTypeKind.Complex: obj2 = this.CreateODataCollection(annotation3.ElementType, null, value, null); goto Label_0155; } break; } default: throw new NotSupportedException(System.Data.Services.Client.Strings.Serializer_InvalidParameterType(paramName, orCreateEdmType.TypeKind)); } throw new NotSupportedException(System.Data.Services.Client.Strings.Serializer_InvalidCollectionParamterItemType(paramName, annotation3.EdmType.TypeKind)); } Label_0155: str = ODataUriUtils.ConvertToUriLiteral(obj2, CommonUtil.ConvertToODataVersion(this.requestInfo.MaxProtocolVersionAsVersion)); if (flag) { return(DataStringEscapeBuilder.EscapeDataString(str)); } return(Uri.EscapeDataString(str)); }
private string ConvertToEscapedUriValue(string paramName, object value) { Debug.Assert(!string.IsNullOrEmpty(paramName), "!string.IsNullOrEmpty(paramName)"); Object valueInODataFormat = null; // Literal values with single quotes need special escaping due to System.Uri changes in behavior between .NET 4.0 and 4.5. // We need to ensure that our escaped values do not change between those versions, so we need to escape values differently when they could contain single quotes. bool needsSpecialEscaping = false; if (value == null) { needsSpecialEscaping = true; } else { if (value.GetType() == typeof(ODataUriNullValue)) { valueInODataFormat = value; needsSpecialEscaping = true; } else { ClientEdmModel model = this.requestInfo.Model; IEdmType edmType = model.GetOrCreateEdmType(value.GetType()); Debug.Assert(edmType != null, "edmType != null"); switch (edmType.TypeKind) { case EdmTypeKind.Primitive: valueInODataFormat = value; needsSpecialEscaping = true; break; case EdmTypeKind.Complex: ClientTypeAnnotation typeAnnotation = model.GetClientTypeAnnotation(edmType); Debug.Assert(typeAnnotation != null, "typeAnnotation != null"); valueInODataFormat = this.propertyConverter.CreateODataComplexValue( typeAnnotation.ElementType, value, null /*propertyName*/, false /*isCollectionItemType*/, null /*visitedComplexTypeObjects*/); // When using JsonVerbose to format query string parameters for Actions, // we cannot write out Complex values in the URI without the type name of the complex type in the JSON payload. // If this value is null, the client has to set the ResolveName property on the DataServiceContext instance. ODataComplexValue complexValue = (ODataComplexValue)valueInODataFormat; SerializationTypeNameAnnotation serializedTypeNameAnnotation = complexValue.GetAnnotation <SerializationTypeNameAnnotation>(); if (serializedTypeNameAnnotation == null || string.IsNullOrEmpty(serializedTypeNameAnnotation.TypeName)) { throw Error.InvalidOperation(Strings.DataServiceException_GeneralError); } break; case EdmTypeKind.Collection: IEdmCollectionType edmCollectionType = edmType as IEdmCollectionType; Debug.Assert(edmCollectionType != null, "edmCollectionType != null"); IEdmTypeReference itemTypeReference = edmCollectionType.ElementType; Debug.Assert(itemTypeReference != null, "itemTypeReference != null"); ClientTypeAnnotation itemTypeAnnotation = model.GetClientTypeAnnotation(itemTypeReference.Definition); Debug.Assert(itemTypeAnnotation != null, "itemTypeAnnotation != null"); switch (itemTypeAnnotation.EdmType.TypeKind) { // We only support primitive or complex type as a collection item type. case EdmTypeKind.Primitive: case EdmTypeKind.Complex: break; default: throw new NotSupportedException(Strings.Serializer_InvalidCollectionParamterItemType(paramName, itemTypeAnnotation.EdmType.TypeKind)); } valueInODataFormat = this.propertyConverter.CreateODataCollection( itemTypeAnnotation.ElementType, null /*propertyName*/, value, null /*visitedComplexTypeObjects*/); break; default: // EdmTypeKind.Entity // EdmTypeKind.Row // EdmTypeKind.EntityReference // EdmTypeKind.Enum. throw new NotSupportedException(Strings.Serializer_InvalidParameterType(paramName, edmType.TypeKind)); } } Debug.Assert(valueInODataFormat != null, "valueInODataFormat != null"); } // In the released WCF Data Services 5.0, we didn't pass the model for JSON Verbose literals, so continuing that behavior for backward compatibility ODataFormat literalFormat = this.requestInfo.Format.UriLiteralFormat; IEdmModel edmModel = literalFormat == ODataFormat.VerboseJson ? null : this.requestInfo.Model; // ODL can handle null values so we can send null values here. string literal = ODataUriUtils.ConvertToUriLiteral(valueInODataFormat, CommonUtil.ConvertToODataVersion(this.requestInfo.MaxProtocolVersionAsVersion), edmModel, literalFormat); // The value from ConvertToUriValue will not be escaped, but will already contain literal delimiters like single quotes, so we // need to use our own escape method that will preserve those characters instead of directly calling Uri.EscapeDataString that may escape them. // This is only necessary for primitives and nulls because the other structures are serialized using the JSON format and it uses double quotes // which have always been escaped. if (needsSpecialEscaping) { return(DataStringEscapeBuilder.EscapeDataString(literal)); } return(Uri.EscapeDataString(literal)); }