static SecureConversationVersion () { var dic = new XmlDictionary (); WSSecureConversation13 = new SecureConversationVersionImpl () { Prefix = dic.Add ("wsse"), Namespace = dic.Add ("http://schemas.xmlsoap.org/ws/2002/12/secext") }; WSSecureConversationFeb2005 = new SecureConversationVersionImpl () { Prefix = dic.Add ("wsse"), Namespace = dic.Add ("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd") }; Default = WSSecureConversation13; }
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { if (type == null) throw new ArgumentNullException("type"); if (declaredType == null) throw new ArgumentNullException("declaredType"); if (knownTypeResolver == null) throw new ArgumentNullException("knownTypeResolver"); if (knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace)) return true; if (type.IsPrimitive && declaredType == typeof(object)) { return knownTypeResolver.TryResolveType(type, type, knownTypeResolver, out typeName, out typeNamespace); } XmlDictionary dict = new XmlDictionary(); typeNamespace = dict.Add(xmlNamespace); typeName = dict.Add(type.AssemblyQualifiedName); return true; }
/// <summary> /// Override this method to map a data contract type to an xsi:type name and namespace during serialization. /// </summary> /// <param name="type">The type to map.</param> /// <param name="declaredType">The type declared in the data contract.</param> /// <param name="knownTypeResolver">The known type resolver.</param> /// <param name="typeName">The xsi:type name.</param> /// <param name="typeNamespace">The xsi:type namespace.</param> /// <returns> /// true if mapping succeeded; otherwise, false. /// </returns> public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { if (type == typeof(Tag)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add("Tag"); typeNamespace = dictionary.Add(uri); return true; } else if (type == typeof(Entry)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add("Entry"); typeNamespace = dictionary.Add(uri); return true; } else if (type == typeof(LinkEntry)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add("LinkEntry"); typeNamespace = dictionary.Add(uri); return true; } else if (type == typeof(LinkItem)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add("LinkItem"); typeNamespace = dictionary.Add(uri); return true; } else return knownTypeResolver.TryResolveType(type, declaredType, knownTypeResolver, out typeName, out typeNamespace); }
// Serialization public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { Type[] genericTypes = type.GetGenericArguments(); string ns = string.Empty; Type genericType = null; foreach (Type genType in genericTypes) { if (typesByType.ContainsKey(genType) == true) { typesByType.TryGetValue(genType, out ns); genericType = genType; break; } } if (string.IsNullOrEmpty(ns) == false) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add(genericType.Name); typeNamespace = dictionary.Add(ns); return true; } else { return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace); } }
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { var res = knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace); if (res) return res; System.Reflection.Assembly asm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(p => p == dataContractType.Assembly); if (asm != null) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add(dataContractType.Name); typeNamespace = dictionary.Add("http://tempuri.com/" + asm.FullName); return true; } foreach (IPlugin plugin in PluginHelper.plugins.Values) { if (plugin.GetType().Assembly == dataContractType.Assembly){ XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add(dataContractType.Name); typeNamespace = dictionary.Add("http://tempuri.com/"+ plugin.Name); return true; } } return false; }
static TrustVersion () { var dic = new XmlDictionary (); WSTrust13 = new TrustVersionImpl () { Prefix = dic.Add ("wst"), Namespace = dic.Add ("http://docs.oasis-open.org/ws-sx/ws-trust/200512") }; WSTrustFeb2005 = new TrustVersionImpl () { Prefix = dic.Add ("wsse"), Namespace = dic.Add ("http://schemas.xmlsoap.org/ws/2002/12/secext") }; Default = WSTrust13; }
public InvalidDataContractCriticalHelper(Type type) : base(type) { StableName = DataContract.GetStableName(type); _xmlDictionary = new XmlDictionary(2); this.Name = this.TopLevelElementName = _xmlDictionary.Add(StableName.Name); this.Namespace = this.TopLevelElementNamespace = _xmlDictionary.Add(StableName.Namespace); }
internal static DataContractSerializer CreateSerializer(Type type, IList<Type> knownTypes, string rootName, string rootNs, int maxItems) { XmlDictionary dictionary = new XmlDictionary(2); return new DataContractSerializer( type, dictionary.Add(rootName), dictionary.Add(rootNs), knownTypes); }
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { if (!knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add(dataContractType.FullName); typeNamespace = dictionary.Add(dataContractType.Assembly.FullName); } return true; }
public NetDataContractSerializer(string rootName, string rootNamespace, StreamingContext context, int maxItemsInObjectGraph, bool ignoreExtensionDataObject, FormatterAssemblyStyle assemblyFormat, ISurrogateSelector surrogateSelector) { XmlDictionary dictionary = new XmlDictionary(2); Initialize(dictionary.Add(rootName), dictionary.Add(DataContract.GetNamespace(rootNamespace)), context, maxItemsInObjectGraph, ignoreExtensionDataObject, assemblyFormat, surrogateSelector); }
public override bool TryResolveType( Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { var dict = new XmlDictionary(); typeName = dict.Add(Uri.EscapeDataString(type.FullName).Replace("%", "..")); typeNamespace = dict.Add(type.Namespace); return true; }
public void TryAddIndex () { XmlDictionary dic = new XmlDictionary (); XmlDictionaryString d1 = dic.Add ("foo"); XmlDictionaryString d2 = dic.Add ("bar"); XmlDictionaryString d3 = dic.Add ("baz"); XmlBinaryWriterSession s = new XmlBinaryWriterSession (); int idx; s.TryAdd (d1, out idx); Assert.AreEqual (0, idx, "#1"); s.TryAdd (d3, out idx); Assert.AreEqual (1, idx, "#2"); // not 2 }
public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { if (Identity.ContainsKey(dataContractType)) { var dictionary = new XmlDictionary(); typeName = dictionary.Add(Identity[dataContractType]); typeNamespace = dictionary.Add(dataContractType.FullName); return true; } // Defer to the known type resolver return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace); }
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { if (type.Assembly.GetName().Name == DynamicTypeBuilder.AssemblyName) { XmlDictionary dic = new XmlDictionary(); typeName = dic.Add(type.Name); typeNamespace = dic.Add(ResolverNamespace); return true; } else { return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace); } }
public override bool TryResolveType (Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { var map = serializer.InternalKnownTypes.FindUserMap (type); if (map == null) { typeName = null; typeNamespace = null; return false; } else { dictionary = dictionary ?? new XmlDictionary (); typeName = dictionary.Add (map.XmlName.Name); typeNamespace = dictionary.Add (map.XmlName.Namespace); return true; } }
// These methods are necessary for standard .Net serialisation // For JSon we use different means, have a look in JsonBinSerializer for its custom Json.NET handler. public override bool TryResolveType(Type dataContractType, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { if (TypeIdentity.Instance.ContainsKey(dataContractType)) { XmlDictionary dictionary = new XmlDictionary(); typeName = dictionary.Add(TypeIdentity.Instance[dataContractType].Alias); typeNamespace = dictionary.Add(dataContractType.FullName); return true; // indicating that this resolver knows how to handle } else { // Defer to the known type resolver return knownTypeResolver.TryResolveType(dataContractType, declaredType, null, out typeName, out typeNamespace); } }
public PrimitiveOperationFormatter(OperationDescription description, bool isRpc) { if (description == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); OperationFormatter.Validate(description, isRpc, false/*isEncoded*/); this.operation = description; #pragma warning suppress 56506 // Microsoft, OperationDescription.Messages never be null this.requestMessage = description.Messages[0]; if (description.Messages.Count == 2) this.responseMessage = description.Messages[1]; int stringCount = 3 + requestMessage.Body.Parts.Count; if (responseMessage != null) stringCount += 2 + responseMessage.Body.Parts.Count; XmlDictionary dictionary = new XmlDictionary(stringCount * 2); xsiNilLocalName = dictionary.Add("nil"); xsiNilNamespace = dictionary.Add(System.Xml.Schema.XmlSchema.InstanceNamespace); OperationFormatter.GetActions(description, dictionary, out this.action, out this.replyAction); if (requestMessage.Body.WrapperName != null) { requestWrapperName = AddToDictionary(dictionary, requestMessage.Body.WrapperName); requestWrapperNamespace = AddToDictionary(dictionary, requestMessage.Body.WrapperNamespace); } requestParts = AddToDictionary(dictionary, requestMessage.Body.Parts, isRpc); if (responseMessage != null) { if (responseMessage.Body.WrapperName != null) { responseWrapperName = AddToDictionary(dictionary, responseMessage.Body.WrapperName); responseWrapperNamespace = AddToDictionary(dictionary, responseMessage.Body.WrapperNamespace); } responseParts = AddToDictionary(dictionary, responseMessage.Body.Parts, isRpc); if (responseMessage.Body.ReturnValue != null && responseMessage.Body.ReturnValue.Type != typeof(void)) { returnPart = AddToDictionary(dictionary, responseMessage.Body.ReturnValue, isRpc); } } }
public void IsLocalName () { XmlDictionaryReader r = GetReader ("<root/>"); r.Read (); Assert.IsTrue (r.IsLocalName ("root"), "#1"); Assert.IsFalse (r.IsLocalName ("foo"), "#2"); XmlDictionaryString ds; XmlDictionary dict = new XmlDictionary (); dict.Add ("root"); dict.TryLookup ("root", out ds); Assert.IsTrue (r.IsLocalName (ds), "#3"); dict.Add ("foo"); dict.TryLookup ("foo", out ds); Assert.IsFalse (r.IsLocalName (ds), "#4"); }
static void Main(string[] args) { List<XmlDictionaryString> dictionaryStringList = new List<XmlDictionaryString>(); XmlDictionary dictionary = new XmlDictionary(); dictionaryStringList.Add(dictionary.Add("Employee")); dictionaryStringList.Add(dictionary.Add("Id")); dictionaryStringList.Add(dictionary.Add("Name")); dictionaryStringList.Add(dictionary.Add("Gender")); dictionaryStringList.Add(dictionary.Add("Department")); Console.WriteLine("{0,-4}{1}", "Key", "Value"); Console.WriteLine(new string('-', 20)); foreach (XmlDictionaryString dictionaryString in dictionaryStringList) { Console.WriteLine("{0,-4}{1}", dictionaryString.Key, dictionaryString.Value); } }
public PrimitiveOperationFormatter(OperationDescription description, bool isRpc) { if (description == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); OperationFormatter.Validate(description, isRpc, false/*isEncoded*/); _operation = description; _requestMessage = description.Messages[0]; if (description.Messages.Count == 2) _responseMessage = description.Messages[1]; int stringCount = 3 + _requestMessage.Body.Parts.Count; if (_responseMessage != null) stringCount += 2 + _responseMessage.Body.Parts.Count; XmlDictionary dictionary = new XmlDictionary(stringCount * 2); _xsiNilLocalName = dictionary.Add("nil"); _xsiNilNamespace = dictionary.Add(EndpointAddressProcessor.XsiNs); OperationFormatter.GetActions(description, dictionary, out _action, out _replyAction); if (_requestMessage.Body.WrapperName != null) { _requestWrapperName = AddToDictionary(dictionary, _requestMessage.Body.WrapperName); _requestWrapperNamespace = AddToDictionary(dictionary, _requestMessage.Body.WrapperNamespace); } _requestParts = AddToDictionary(dictionary, _requestMessage.Body.Parts, isRpc); if (_responseMessage != null) { if (_responseMessage.Body.WrapperName != null) { _responseWrapperName = AddToDictionary(dictionary, _responseMessage.Body.WrapperName); _responseWrapperNamespace = AddToDictionary(dictionary, _responseMessage.Body.WrapperNamespace); } _responseParts = AddToDictionary(dictionary, _responseMessage.Body.Parts, isRpc); if (_responseMessage.Body.ReturnValue != null && _responseMessage.Body.ReturnValue.Type != typeof(void)) { _returnPart = AddToDictionary(dictionary, _responseMessage.Body.ReturnValue, isRpc); } } }
public void Add () { XmlDictionary d = new XmlDictionary (); Assert.AreEqual (0, d.Add ("foo").Key, "#1"); Assert.AreEqual (0, d.Add ("foo").Key, "#2"); Assert.AreEqual (1, d.Add ("bar").Key, "#3"); Assert.AreEqual (2, d.Add ("baz").Key, "#4"); }
public void Empty () { XmlDictionary d = new XmlDictionary (); XmlDictionaryString dns; d.Add (String.Empty); Assert.IsTrue (d.TryLookup (String.Empty, out dns), "#0"); Assert.AreEqual (0, dns.Key, "#1"); }
/// <summary> /// Tries to resolve whether a type is known. /// Is used for serialization. /// Gets called by the framework. /// </summary> /// <param name="type"></param> /// <param name="declaredType"></param> /// <param name="knownTypeResolver"></param> /// <param name="typeName"></param> /// <param name="typeNamespace"></param> /// <returns></returns> public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { Logger.Debug(String.Format("BusDataContractResolver: TryResolveType(type='{0}', declaredType='{1}')", type.FullName, declaredType.FullName)); if (ServiceHelper.IsServiceValidType(type)) { XmlDictionary dictionary = new XmlDictionary(); string encodedTypeName = Encoding.Encoder.SafeEncode(type.FullName); Logger.Debug(String.Format("BusDataContractResolver: TryResolveType() got valid type: '{0}'. Encoded name: '{1}'.", type.FullName, encodedTypeName)); typeName = dictionary.Add(encodedTypeName); typeNamespace = dictionary.Add("http://tempuri.com"); return true; } Logger.Error(String.Format("BusDataContractResolver: TryResolveType() got invalid type: '{0}'.", type.FullName)); return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace); }
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out System.Xml.XmlDictionaryString typeName, out System.Xml.XmlDictionaryString typeNamespace) { Debug.WriteLine("TryResolveType ", type.Name); var retVal = _typeToNames.ContainsKey(type); if (retVal) { XmlDictionary dictionary = new XmlDictionary(); typeNamespace = dictionary.Add(_typeToNames[type].Item1); typeName = dictionary.Add(_typeToNames[type].Item2); } else { retVal = knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace); } return retVal; }
public override bool TryResolveType(Type type, Type declaredType, DataContractResolver knownTypeResolver, out XmlDictionaryString typeName, out XmlDictionaryString typeNamespace) { var fullName = type.FullName; if (_typeToAssemblyLookup.ContainsKey(fullName)) { var dictionary = new XmlDictionary(); typeName = dictionary.Add(fullName); typeNamespace = dictionary.Add(_xmlNamespace); return true; } return knownTypeResolver.TryResolveType(type, declaredType, null, out typeName, out typeNamespace); }
public void TryAddDuplicate () { XmlDictionary dic = new XmlDictionary (); XmlDictionaryString d1 = dic.Add ("foo"); XmlBinaryWriterSession s = new XmlBinaryWriterSession (); int idx; s.TryAdd (d1, out idx); s.TryAdd (d1, out idx); }
private static XmlDictionaryString AddToDictionary(XmlDictionary dictionary, string s) { XmlDictionaryString str; if (!dictionary.TryLookup(s, out str)) { str = dictionary.Add(s); } return str; }
public CoordinationExternal11Dictionary(XmlDictionary dictionary) { this.Namespace = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06"); this.CreateCoordinationContextAction = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext"); this.CreateCoordinationContextResponseAction = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContextResponse"); this.RegisterAction = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06/Register"); this.RegisterResponseAction = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06/RegisterResponse"); this.FaultAction = dictionary.Add("http://docs.oasis-open.org/ws-tx/wscoor/2006/06/fault"); this.CannotCreateContext = dictionary.Add("CannotCreateContext"); this.CannotRegisterParticipant = dictionary.Add("CannotRegisterParticipant"); }
public PrimitiveOperationFormatter(OperationDescription description, bool isRpc) { if (description == null) { throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("description"); } OperationFormatter.Validate(description, isRpc, false); this.operation = description; this.requestMessage = description.Messages[0]; if (description.Messages.Count == 2) { this.responseMessage = description.Messages[1]; } int num = 3 + this.requestMessage.Body.Parts.Count; if (this.responseMessage != null) { num += 2 + this.responseMessage.Body.Parts.Count; } XmlDictionary dictionary = new XmlDictionary(num * 2); this.xsiNilLocalName = dictionary.Add("nil"); this.xsiNilNamespace = dictionary.Add("http://www.w3.org/2001/XMLSchema-instance"); OperationFormatter.GetActions(description, dictionary, out this.action, out this.replyAction); if (this.requestMessage.Body.WrapperName != null) { this.requestWrapperName = AddToDictionary(dictionary, this.requestMessage.Body.WrapperName); this.requestWrapperNamespace = AddToDictionary(dictionary, this.requestMessage.Body.WrapperNamespace); } this.requestParts = AddToDictionary(dictionary, this.requestMessage.Body.Parts, isRpc); if (this.responseMessage != null) { if (this.responseMessage.Body.WrapperName != null) { this.responseWrapperName = AddToDictionary(dictionary, this.responseMessage.Body.WrapperName); this.responseWrapperNamespace = AddToDictionary(dictionary, this.responseMessage.Body.WrapperNamespace); } this.responseParts = AddToDictionary(dictionary, this.responseMessage.Body.Parts, isRpc); if ((this.responseMessage.Body.ReturnValue != null) && (this.responseMessage.Body.ReturnValue.Type != typeof(void))) { this.returnPart = AddToDictionary(dictionary, this.responseMessage.Body.ReturnValue, isRpc); } } }
protected override byte [] EncodeSecurityState (byte [] src) { foreach (byte b in src) Console.Write ("{0:X02} ", b); Console.WriteLine (); // this show how it is LAMESPEC. //Array.Reverse (src); XmlDictionary dic = new XmlDictionary (); for (int i = 0; i < 60; i++) dic.Add ("n" + i); XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas (); XmlDictionaryReader cr = XmlDictionaryReader.CreateBinaryReader (src, 0, src.Length, dic, quotas); cr.Read (); XmlWriter w = XmlWriter.Create (Console.Out); while (!cr.EOF) switch (cr.NodeType) { case XmlNodeType.Element: int dummy; w.WriteStartElement (cr.Prefix, cr.LocalName, cr.NamespaceURI); for (int i = 0; i < cr.AttributeCount; i++) { cr.MoveToAttribute (i); w.WriteStartAttribute (cr.Prefix, cr.LocalName, cr.NamespaceURI); bool b64 = cr.LocalName == "n41"; while (cr.ReadAttributeValue ()) { if (b64) foreach (byte b in Convert.FromBase64String (cr.Value)) w.WriteString (String.Format ("{0:X02}-", b)); else w.WriteString (cr.Value); } w.WriteEndAttribute (); } //w.WriteAttributes (cr, false); cr.MoveToElement (); if (cr.IsEmptyElement) w.WriteEndElement (); cr.Read (); break; case XmlNodeType.EndElement: w.WriteEndElement (); cr.Read (); break; default: if (cr.TryGetBase64ContentLength (out dummy)) { foreach (byte b in cr.ReadContentAsBase64 ()) w.WriteString (String.Format ("{0:X02} ", b)); } else w.WriteNode (cr, false); break; } w.Close (); return src; }