ParameterXPathQueryGenerator.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //------------------------------------------------------------
  4. namespace System.ServiceModel.Description
  5. {
  6. using System.Xml.Linq;
  7. using System.Xml;
  8. using System.Text;
  9. using System.Runtime.Serialization;
  10. using System.ServiceModel.Description;
  11. using System.Reflection;
  12. public static class ParameterXPathQueryGenerator
  13. {
  14. const string XPathSeparator = "/";
  15. const string NsSeparator = ":";
  16. const string ServiceContractPrefix = "xgSc";
  17. public static string CreateFromDataContractSerializer(XName serviceContractName, string operationName, string parameterName, bool isReply, Type type, MemberInfo[] pathToMember, out XmlNamespaceManager namespaces)
  18. {
  19. if (type == null)
  20. {
  21. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("type"));
  22. }
  23. if (pathToMember == null)
  24. {
  25. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("pathToMember"));
  26. }
  27. if (operationName == null)
  28. {
  29. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("operationName"));
  30. }
  31. if (serviceContractName == null)
  32. {
  33. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("serviceContractName"));
  34. }
  35. if (isReply)
  36. {
  37. operationName += TypeLoader.ResponseSuffix;
  38. }
  39. StringBuilder xPathBuilder = new StringBuilder(XPathSeparator + ServiceContractPrefix + NsSeparator + operationName);
  40. xPathBuilder.Append(XPathSeparator + ServiceContractPrefix + NsSeparator + parameterName);
  41. string xpath = XPathQueryGenerator.CreateFromDataContractSerializer(type, pathToMember, xPathBuilder, out namespaces);
  42. string serviceContractNamespace = serviceContractName.NamespaceName;
  43. // Use default service contract namespace if the provided serviceContractNamespace is null or empty
  44. if (string.IsNullOrEmpty(serviceContractNamespace))
  45. {
  46. serviceContractNamespace = NamingHelper.DefaultNamespace;
  47. }
  48. namespaces.AddNamespace(ServiceContractPrefix, serviceContractNamespace);
  49. return xpath;
  50. }
  51. }
  52. }