Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

414 lines
13 KiB

  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Text;
  7. using System.Xml;
  8. using System.Xml.Serialization;
  9. using System.Collections;
  10. using System.Web.Services.Protocols;
  11. using UDDI;
  12. using UDDI.Diagnostics;
  13. using UDDI.API.Business;
  14. using UDDI.API.Service;
  15. using UDDI.API.ServiceType;
  16. using UDDI.API.Authentication;
  17. namespace UDDI.API
  18. {
  19. /// <summary>
  20. /// The Documentation class is an HTTP handler that will redirect (server-side) GET requests to our .ASMX files
  21. /// to a help file.
  22. /// </summary>
  23. public class Documentation : IHttpHandler
  24. {
  25. public void ProcessRequest( HttpContext httpContext )
  26. {
  27. int cultureID = Localization.GetCulture().LCID;
  28. string basepath = "/help/{0}/wsdlinfo.htm";
  29. //
  30. // Validate that the current UI Culture is supported. If not, revert to the default
  31. // language.
  32. //
  33. string pathToHelp = GetFullFilePath( string.Format( basepath,cultureID ) ) ;
  34. if( !System.IO.File.Exists( httpContext.Server.MapPath( pathToHelp ) ) )
  35. {
  36. try
  37. {
  38. cultureID = System.Globalization.CultureInfo.CreateSpecificCulture( Config.GetString( "Setup.WebServer.ProductLanguage", "en-US" ) ).LCID;
  39. }
  40. catch
  41. {
  42. cultureID = new System.Globalization.CultureInfo( Config.GetString( "Setup.WebServer.ProductLanguage", "en-US" ) ).LCID;
  43. }
  44. pathToHelp = GetFullFilePath( string.Format( basepath,cultureID ) );
  45. }
  46. //
  47. // Do a server-side transfer to return the proper help file to the client.
  48. //
  49. httpContext.Server.Transfer( pathToHelp );
  50. }
  51. private static string GetFullFilePath( string file )
  52. {
  53. string url = ( ( "/"==HttpContext.Current.Request.ApplicationPath) ? "" : HttpContext.Current.Request.ApplicationPath );
  54. url += file ;
  55. return url;
  56. }
  57. public bool IsReusable
  58. {
  59. get { return true; }
  60. }
  61. }
  62. [XmlRootAttribute("get_registeredInfo", Namespace=UDDI.API.Constants.Namespace)]
  63. public class GetRegisteredInfo : IAuthenticateable, IMessage
  64. {
  65. //
  66. // Attribute: generic
  67. //
  68. private string generic;
  69. [XmlAttribute("generic")]
  70. public string Generic
  71. {
  72. get { return generic; }
  73. set { generic = value; }
  74. }
  75. //
  76. // Element: authInfo
  77. //
  78. private string authInfo;
  79. [XmlElement("authInfo")]
  80. public string AuthInfo
  81. {
  82. get { return authInfo; }
  83. set { authInfo = value; }
  84. }
  85. }
  86. [XmlRootAttribute("dispositionReport", Namespace=UDDI.API.Constants.Namespace)]
  87. public class DispositionReport
  88. {
  89. [XmlAttribute("generic")]
  90. public string Generic
  91. {
  92. get
  93. {
  94. if( 0 == Context.ApiVersionMajor )
  95. return "2.0";
  96. return Context.ApiVersionMajor.ToString() + ".0";
  97. }
  98. set { }
  99. }
  100. [XmlAttribute("operator")]
  101. public string Operator = Config.GetString( "Operator" );
  102. [XmlAttribute("truncated")]
  103. public string Truncated;
  104. [XmlElement("result")]
  105. public ResultCollection Results = new ResultCollection();
  106. public DispositionReport() : this( ErrorType.E_success, "" )
  107. {
  108. }
  109. public DispositionReport( ErrorType err, string description )
  110. {
  111. Results.Add( err, description );
  112. }
  113. public static void ThrowFinal( UDDIException e )
  114. {
  115. if( 0 == Context.ApiVersionMajor )
  116. Context.ApiVersionMajor = 2;
  117. string versionedNamespace = ( Context.ApiVersionMajor == 1 ? "urn:uddi-org:api" : "urn:uddi-org:api_v2" );
  118. HttpContext.Current.Response.StatusCode = 500;
  119. HttpContext.Current.Response.ContentType = Config.GetString( "Soap.ContentType", @"text/xml; charset=""utf-8""" );
  120. HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
  121. XmlTextWriter soapFault = new XmlTextWriter( HttpContext.Current.Response.Output );
  122. soapFault.WriteStartDocument();
  123. soapFault.WriteStartElement( "soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/" );
  124. soapFault.WriteStartElement( "soap", "Body", "http://schemas.xmlsoap.org/soap/envelope/" );
  125. soapFault.WriteStartElement( "soap", "Fault", "http://schemas.xmlsoap.org/soap/envelope/" );
  126. soapFault.WriteElementString( "soap:faultcode", "soap:Client" );
  127. soapFault.WriteElementString( "soap:faultstring", "" );
  128. soapFault.WriteStartElement( "soap:detail" );
  129. soapFault.WriteStartElement( "dispositionReport" );
  130. soapFault.WriteAttributeString( "generic", "", Context.ApiVersionMajor.ToString() + ".0" );
  131. soapFault.WriteAttributeString( "operator", "", Config.GetString( "Operator" ) );
  132. soapFault.WriteAttributeString( "xmlns", versionedNamespace );
  133. soapFault.WriteStartElement( "result" );
  134. soapFault.WriteAttributeString( "errno", "", ( ( int )e.Number ).ToString() );
  135. soapFault.WriteStartElement( "errInfo" );
  136. soapFault.WriteAttributeString( "errCode", "", e.Number.ToString() );
  137. soapFault.WriteString( UDDI.Utility.XmlEncode( e.Message ) );
  138. soapFault.WriteEndElement();
  139. soapFault.WriteEndElement();
  140. soapFault.WriteEndElement();
  141. soapFault.WriteEndElement();
  142. soapFault.WriteEndElement();
  143. soapFault.WriteEndElement();
  144. soapFault.WriteEndElement();
  145. soapFault.WriteEndDocument();
  146. soapFault.Flush();
  147. HttpContext.Current.Response.Flush();
  148. HttpContext.Current.Response.Close();
  149. HttpContext.Current.Response.End();
  150. }
  151. public static void Throw( Exception e )
  152. {
  153. Debug.Enter();
  154. //
  155. // If this is a UDDI exception get the error number
  156. // Otherwise map all other errors to E_fatalError
  157. //
  158. ErrorType et = ErrorType.E_fatalError;
  159. string debugMessage = "";
  160. if( e is UDDI.UDDIException )
  161. {
  162. et = (ErrorType)( (UDDIException)e ).Number;
  163. }
  164. else if( e is System.Data.SqlClient.SqlException )
  165. {
  166. //
  167. // SECURITY: SqlException's include stored procedure names
  168. // This information is flowing back to the client in the SOAPFault
  169. // information. This information should be logged and not returned.
  170. //
  171. System.Data.SqlClient.SqlException se = (System.Data.SqlClient.SqlException)e;
  172. //
  173. // Build a detailed message about the exception; this text is not sent back to the user.
  174. //
  175. debugMessage = "SQL Exception in " + se.Procedure +
  176. " line " + se.LineNumber +
  177. " [severity " + se.Class +
  178. ", state " + se.State;
  179. debugMessage += ", server " + se.Server;
  180. debugMessage += "]";
  181. //
  182. // Is this one of our custom error messages? If so, we'll masssage the
  183. // error code into one of the UDDIException error types (custom errors
  184. // are thrown as ErrorType + 50000). Otherwise, we'll simply use
  185. // E_fatalError.
  186. //
  187. if( 16 == se.Class )
  188. et = (ErrorType)( se.Number - 50000 );
  189. else
  190. {
  191. //
  192. // 739178 - See if this was a SQL deadlock issue. If it was, then return an E_serverBusy error
  193. // instead. The 1205 number is a retrieved from sysmessages table in the masters database of
  194. // SQL Server. See the SQL Books Online for more information about 1205.
  195. //
  196. if( 1205 == se.Number )
  197. {
  198. //
  199. // Change the 'e' variable to a new exception; need to do this since e.Message
  200. // is read-only. Keep track of the original exception so we can log it.
  201. //
  202. Exception originalException = e;
  203. e = new UDDIException( ErrorType.E_busy, "ERROR_BUSY" );
  204. et = ErrorType.E_busy;
  205. Debug.Write( SeverityType.Info, CategoryType.Data, "A deadlock exception has been converted to an E_busy exception. The original exception was:\r\n" + originalException.ToString() );
  206. }
  207. else
  208. {
  209. et = ErrorType.E_fatalError;
  210. }
  211. }
  212. }
  213. //
  214. // Log this error message.
  215. //
  216. Debug.Write( SeverityType.Info, CategoryType.Data, "An exception occurred. Details Follow:\r\n" + e.ToString() + "\r\n\r\n" + debugMessage );
  217. //
  218. // if this is a V1.0 call, map any new V2.0 error codes to
  219. // v1.0 error codes
  220. //
  221. if( 1 == Context.ApiVersionMajor )
  222. {
  223. switch( et )
  224. {
  225. case ErrorType.E_invalidValue:
  226. case ErrorType.E_valueNotAllowed:
  227. case ErrorType.E_invalidProjection:
  228. case ErrorType.E_assertionNotFound:
  229. case ErrorType.E_invalidCompletionStatus:
  230. case ErrorType.E_messageTooLarge:
  231. case ErrorType.E_transferAborted:
  232. case ErrorType.E_publisherCancelled:
  233. case ErrorType.E_requestDenied:
  234. case ErrorType.E_secretUnknown:
  235. et = ErrorType.E_fatalError;
  236. break;
  237. }
  238. }
  239. //
  240. // Construct a new instance of a disposition report
  241. //
  242. DispositionReport dr = new DispositionReport( et, e.Message );
  243. //
  244. // Serialize the disposition report to a stream and load into
  245. // a DOM.
  246. //
  247. XmlDocument doc = new XmlDocument();
  248. MemoryStream strm = new MemoryStream();
  249. // XmlSerializer serializer = new XmlSerializer( typeof( DispositionReport ) );
  250. XmlSerializer serializer = XmlSerializerManager.GetSerializer( typeof( DispositionReport ) );
  251. serializer.Serialize( strm, dr );
  252. strm.Position = 0;
  253. doc.Load( strm );
  254. //
  255. // Wrap the disposition report with a detail node.
  256. //
  257. XmlNode detail = doc.CreateNode(
  258. XmlNodeType.Element,
  259. SoapException.DetailElementName.Name,
  260. SoapException.DetailElementName.Namespace );
  261. detail.AppendChild( doc.FirstChild.NextSibling );
  262. //
  263. // Construct the SOAP exception using the dr XML
  264. // as details and the received Exception as the inner exception.
  265. //
  266. UDDIText uddiText = new UDDIText( "ERROR_FATAL_ERROR" );
  267. throw new UDDISoapException( uddiText.GetText(),
  268. SoapException.ClientFaultCode,
  269. "",
  270. detail,
  271. e);
  272. }
  273. }
  274. /// <summary>
  275. /// Soap Exception Wrapper to help prevent StackTrace dumps in the XML output sent from the server.
  276. ///
  277. /// NOTE: ASP.NET will call Exception.ToString() to get the stack trace, so in Release/Free builds,
  278. /// we only return an empty string, other wise we return the entire dump.
  279. /// </summary>
  280. public class UDDISoapException : SoapException
  281. {
  282. public UDDISoapException( string message, XmlQualifiedName name, string actor, XmlNode detail, Exception e ) : base( message, name, actor, detail, e )
  283. {}
  284. public override string ToString()
  285. {
  286. #if DEBUG
  287. return base.ToString();
  288. #else
  289. return "";
  290. #endif
  291. }
  292. }
  293. [XmlRootAttribute("registeredInfo", Namespace=UDDI.API.Constants.Namespace)]
  294. public class RegisteredInfo
  295. {
  296. [XmlAttribute("generic")]
  297. public string Generic = UDDI.API.Constants.Version;
  298. [XmlAttribute("operator")]
  299. public string Operator = Config.GetString( "Operator" );
  300. [XmlAttribute("truncated")]
  301. public string Truncated;
  302. [ XmlArray( "businessInfos" ), XmlArrayItem( "businessInfo" ) ]
  303. public BusinessInfoCollection BusinessInfos = new BusinessInfoCollection();
  304. [ XmlArray( "tModelInfos" ), XmlArrayItem( "tModelInfo" ) ]
  305. public TModelInfoCollection TModelInfos = new TModelInfoCollection();
  306. public void Get()
  307. {
  308. BusinessInfos.GetForCurrentPublisher();
  309. TModelInfos.GetForCurrentPublisher();
  310. }
  311. }
  312. [XmlRootAttribute("validate_categorization", Namespace=UDDI.API.Constants.Namespace)]
  313. public class ValidateCategorization : IMessage
  314. {
  315. //
  316. // Attribute: generic
  317. //
  318. private string generic;
  319. [XmlAttribute("generic")]
  320. public string Generic
  321. {
  322. get { return generic; }
  323. set { generic = value; }
  324. }
  325. [XmlElement("tModelKey")]
  326. public string TModelKey = "";
  327. [XmlElement("keyValue")]
  328. public string KeyValue = "";
  329. [XmlElement("businessEntity")]
  330. public BusinessEntity BusinessEntity = new BusinessEntity();
  331. [XmlElement("businessService")]
  332. public BusinessService BusinessService = new BusinessService();
  333. [XmlElement("tModel")]
  334. public TModel TModel = new TModel();
  335. internal void Validate()
  336. {
  337. SqlCommand cmd = new SqlCommand( "net_categoryBag_validate", ConnectionManager.GetConnection() );
  338. cmd.Transaction = ConnectionManager.GetTransaction();
  339. cmd.CommandType = CommandType.StoredProcedure;
  340. cmd.Parameters.Add( new SqlParameter( "@keyValue", SqlDbType.NVarChar, UDDI.Constants.Lengths.KeyValue ) ).Direction = ParameterDirection.Input;
  341. cmd.Parameters.Add( new SqlParameter( "@tModelKey", SqlDbType.UniqueIdentifier ) ).Direction = ParameterDirection.Input;
  342. SqlParameterAccessor paramacc = new SqlParameterAccessor( cmd.Parameters );
  343. paramacc.SetString( "@keyValue", KeyValue );
  344. paramacc.SetGuidFromKey( "@tModelKey", TModelKey );
  345. cmd.ExecuteNonQuery();
  346. }
  347. }
  348. }