// Convert a byte buffer into a hex string. internal static String ToHex(byte[] buffer) { if (buffer == null) { return(String.Empty); } StringBuilder builder = new StringBuilder(); int posn; for (posn = 0; posn < buffer.Length; ++posn) { BitConverter.AppendHex(builder, buffer[posn]); } return(builder.ToString()); }
// Encode SOAP names. public static String CodeXmlNamespaceForClrTypeNamespace (String typeNamespace, String assemblyName) { StringBuilder builder = new StringBuilder(); // Add the URI prefix and type name to the builder. if (typeNamespace != null && typeNamespace.Length > 0) { if (assemblyName != null && assemblyName.Length > 0) { // We have both type and assembly names. builder.Append(XmlNsForClrTypeWithNsAndAssembly); if (typeNamespace[0] != '.') { builder.Append(typeNamespace); } else { // Strip a leading ".", if present. builder.Append(typeNamespace, 1, typeNamespace.Length - 1); } builder.Append(typeNamespace); builder.Append('/'); } else { // We have only a type name. builder.Append(XmlNsForClrTypeWithNs); builder.Append(typeNamespace); return(builder.ToString()); } } else if (assemblyName != null && assemblyName.Length > 0) { // We have only an assembly name. builder.Append(XmlNsForClrTypeWithAssembly); } else { // Neither name was supplied. throw new ArgumentNullException ("typeNamespace & assemblyName"); } // Encode the assembly name and add it to the builder. foreach (char ch in assemblyName) { if (ch == ' ' || ch == '=' || ch == ',' || ch == '%') { builder.Append('%'); BitConverter.AppendHex(builder, (int)ch); } else { builder.Append(ch); } } // Return the final string to the caller. return(builder.ToString()); }