MexServiceChannelBuilder.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) Microsoft Corporation. All rights reserved.
  3. //-----------------------------------------------------------------------------
  4. #pragma warning disable 1634, 1691
  5. namespace System.ServiceModel.ComIntegration
  6. {
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Diagnostics;
  11. using System.Runtime;
  12. using System.Runtime.InteropServices;
  13. using System.ServiceModel;
  14. using System.ServiceModel.Channels;
  15. using System.ServiceModel.Description;
  16. using System.ServiceModel.Diagnostics;
  17. using System.ServiceModel.Dispatcher;
  18. using System.Threading;
  19. using System.Xml;
  20. using System.Xml.Schema;
  21. using ConfigNS = System.ServiceModel.Configuration;
  22. using DiscoNS = System.Web.Services.Discovery;
  23. using WsdlNS = System.Web.Services.Description;
  24. class MexServiceChannelBuilder : IProxyCreator, IProvideChannelBuilderSettings
  25. {
  26. ContractDescription contractDescription = null;
  27. ServiceChannelFactory serviceChannelFactory = null;
  28. Dictionary<MonikerHelper.MonikerAttribute, string> propertyTable;
  29. // Double-checked locking pattern requires volatile for read/write synchronization
  30. volatile ServiceChannel serviceChannel = null;
  31. ServiceEndpoint serviceEndpoint = null;
  32. KeyedByTypeCollection<IEndpointBehavior> behaviors = new KeyedByTypeCollection<IEndpointBehavior>();
  33. bool useXmlSerializer = false;
  34. //Suppressing PreSharp warning that property get methods should not throw
  35. #pragma warning disable 6503
  36. ServiceChannelFactory IProvideChannelBuilderSettings.ServiceChannelFactoryReadWrite
  37. {
  38. get
  39. {
  40. if (serviceChannel != null)
  41. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.TooLate), HR.RPC_E_TOO_LATE));
  42. return serviceChannelFactory;
  43. }
  44. }
  45. #pragma warning restore 6503
  46. ServiceChannel IProvideChannelBuilderSettings.ServiceChannel
  47. {
  48. get
  49. {
  50. return CreateChannel();
  51. }
  52. }
  53. ServiceChannelFactory IProvideChannelBuilderSettings.ServiceChannelFactoryReadOnly
  54. {
  55. get
  56. {
  57. return serviceChannelFactory;
  58. }
  59. }
  60. //Suppressing PreSharp warning that property get methods should not throw
  61. #pragma warning disable 6503
  62. KeyedByTypeCollection<IEndpointBehavior> IProvideChannelBuilderSettings.Behaviors
  63. {
  64. get
  65. {
  66. if (serviceChannel != null)
  67. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.TooLate), HR.RPC_E_TOO_LATE));
  68. return behaviors;
  69. }
  70. }
  71. #pragma warning restore 6503
  72. void IDisposable.Dispose()
  73. {
  74. if (serviceChannel != null)
  75. serviceChannel.Close();
  76. }
  77. internal MexServiceChannelBuilder(Dictionary<MonikerHelper.MonikerAttribute, string> propertyTable)
  78. {
  79. this.propertyTable = propertyTable;
  80. DoMex();
  81. }
  82. ServiceChannel CreateChannel()
  83. {
  84. if (serviceChannel == null)
  85. {
  86. lock (this)
  87. {
  88. if (serviceChannel == null)
  89. {
  90. try
  91. {
  92. if (serviceChannelFactory == null)
  93. {
  94. FaultInserviceChannelFactory();
  95. }
  96. if (serviceChannelFactory == null)
  97. {
  98. throw Fx.AssertAndThrow("ServiceChannelFactory cannot be null at this point");
  99. }
  100. serviceChannelFactory.Open();
  101. if (serviceEndpoint == null)
  102. {
  103. throw Fx.AssertAndThrow("ServiceEndpoint cannot be null");
  104. }
  105. ServiceChannel localChannel = serviceChannelFactory.CreateServiceChannel(new EndpointAddress(serviceEndpoint.Address.Uri, serviceEndpoint.Address.Identity, serviceEndpoint.Address.Headers), serviceEndpoint.Address.Uri);
  106. serviceChannel = localChannel;
  107. ComPlusChannelCreatedTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationChannelCreated,
  108. SR.TraceCodeComIntegrationChannelCreated, serviceEndpoint.Address.Uri, contractDescription.ContractType);
  109. if (serviceChannel == null)
  110. {
  111. throw Fx.AssertAndThrow("serviceProxy MUST derive from RealProxy");
  112. }
  113. }
  114. finally
  115. {
  116. if ((serviceChannel == null) && (serviceChannelFactory != null))
  117. {
  118. serviceChannelFactory.Close();
  119. }
  120. }
  121. }
  122. }
  123. }
  124. return serviceChannel;
  125. }
  126. private ServiceChannelFactory CreateServiceChannelFactory()
  127. {
  128. serviceChannelFactory = ServiceChannelFactory.BuildChannelFactory(serviceEndpoint) as ServiceChannelFactory;
  129. if (serviceChannelFactory == null)
  130. {
  131. throw Fx.AssertAndThrow("We should get a ServiceChannelFactory back");
  132. }
  133. FixupProxyBehavior();
  134. return serviceChannelFactory;
  135. }
  136. void FaultInserviceChannelFactory()
  137. {
  138. if (propertyTable == null)
  139. {
  140. throw Fx.AssertAndThrow("PropertyTable should not be null");
  141. }
  142. foreach (IEndpointBehavior behavior in behaviors)
  143. serviceEndpoint.Behaviors.Add(behavior);
  144. serviceChannelFactory = CreateServiceChannelFactory();
  145. }
  146. void FixupProxyBehavior()
  147. {
  148. ClientOperation operation = null;
  149. if (useXmlSerializer)
  150. XmlSerializerOperationBehavior.AddBehaviors(contractDescription);
  151. foreach (OperationDescription opDesc in contractDescription.Operations)
  152. {
  153. operation = serviceChannelFactory.ClientRuntime.Operations[opDesc.Name];
  154. operation.SerializeRequest = true;
  155. operation.DeserializeReply = true;
  156. if (useXmlSerializer)
  157. operation.Formatter = XmlSerializerOperationBehavior.CreateOperationFormatter(opDesc);
  158. else
  159. operation.Formatter = new DataContractSerializerOperationFormatter(opDesc, TypeLoader.DefaultDataContractFormatAttribute, null);
  160. }
  161. }
  162. private void DoMex()
  163. {
  164. string mexAddress;
  165. string mexBindingSectionName;
  166. string mexBindingConfiguration;
  167. string contract;
  168. string contractNamespace;
  169. string binding;
  170. string bindingNamespace;
  171. string address;
  172. string spnIdentity = null;
  173. string upnIdentity = null;
  174. string dnsIdentity = null;
  175. string mexSpnIdentity = null;
  176. string mexUpnIdentity = null;
  177. string mexDnsIdentity = null;
  178. string serializer = null;
  179. EndpointIdentity identity = null;
  180. EndpointIdentity mexIdentity = null;
  181. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out contract);
  182. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out contractNamespace);
  183. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out bindingNamespace);
  184. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out binding);
  185. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexAddress, out mexAddress);
  186. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBinding, out mexBindingSectionName);
  187. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBindingConfiguration, out mexBindingConfiguration);
  188. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Address, out address);
  189. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.SpnIdentity, out spnIdentity);
  190. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.UpnIdentity, out upnIdentity);
  191. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.DnsIdentity, out dnsIdentity);
  192. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexSpnIdentity, out mexSpnIdentity);
  193. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexUpnIdentity, out mexUpnIdentity);
  194. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexDnsIdentity, out mexDnsIdentity);
  195. propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Serializer, out serializer);
  196. if (string.IsNullOrEmpty(mexAddress))
  197. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexAddressNotSpecified)));
  198. if (!string.IsNullOrEmpty(mexSpnIdentity))
  199. {
  200. if ((!string.IsNullOrEmpty(mexUpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity)))
  201. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex)));
  202. mexIdentity = EndpointIdentity.CreateSpnIdentity(mexSpnIdentity);
  203. }
  204. else if (!string.IsNullOrEmpty(mexUpnIdentity))
  205. {
  206. if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity)))
  207. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex)));
  208. mexIdentity = EndpointIdentity.CreateUpnIdentity(mexUpnIdentity);
  209. }
  210. else if (!string.IsNullOrEmpty(mexDnsIdentity))
  211. {
  212. if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexUpnIdentity)))
  213. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex)));
  214. mexIdentity = EndpointIdentity.CreateDnsIdentity(mexDnsIdentity);
  215. }
  216. else
  217. mexIdentity = null;
  218. if (string.IsNullOrEmpty(address))
  219. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerAddressNotSpecified)));
  220. if (string.IsNullOrEmpty(contract))
  221. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotSpecified)));
  222. if (string.IsNullOrEmpty(binding))
  223. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNotSpecified)));
  224. if (string.IsNullOrEmpty(bindingNamespace))
  225. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNamespacetNotSpecified)));
  226. if (!string.IsNullOrEmpty(spnIdentity))
  227. {
  228. if ((!string.IsNullOrEmpty(upnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity)))
  229. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity)));
  230. identity = EndpointIdentity.CreateSpnIdentity(spnIdentity);
  231. }
  232. else if (!string.IsNullOrEmpty(upnIdentity))
  233. {
  234. if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity)))
  235. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity)));
  236. identity = EndpointIdentity.CreateUpnIdentity(upnIdentity);
  237. }
  238. else if (!string.IsNullOrEmpty(dnsIdentity))
  239. {
  240. if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(upnIdentity)))
  241. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity)));
  242. identity = EndpointIdentity.CreateDnsIdentity(dnsIdentity);
  243. }
  244. else
  245. identity = null;
  246. MetadataExchangeClient resolver = null;
  247. EndpointAddress mexEndpointAddress = new EndpointAddress(new Uri(mexAddress), mexIdentity);
  248. if (!string.IsNullOrEmpty(mexBindingSectionName))
  249. {
  250. Binding mexBinding = null;
  251. try
  252. {
  253. mexBinding = ConfigLoader.LookupBinding(mexBindingSectionName, mexBindingConfiguration);
  254. }
  255. catch (System.Configuration.ConfigurationErrorsException)
  256. {
  257. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName)));
  258. }
  259. if (null == mexBinding)
  260. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName)));
  261. resolver = new MetadataExchangeClient(mexBinding);
  262. }
  263. else if (string.IsNullOrEmpty(mexBindingConfiguration))
  264. resolver = new MetadataExchangeClient(mexEndpointAddress);
  265. else
  266. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexBindingSectionNameNotSpecified)));
  267. if (null != mexIdentity)
  268. {
  269. // To disable AllowNtlm warning.
  270. #pragma warning disable 618
  271. resolver.SoapCredentials.Windows.AllowNtlm = false;
  272. #pragma warning restore 618
  273. }
  274. bool removeXmlSerializerImporter = false;
  275. if (!String.IsNullOrEmpty(serializer))
  276. {
  277. if ("xml" != serializer && "datacontract" != serializer)
  278. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorectSerializer)));
  279. if ("xml" == serializer)
  280. useXmlSerializer = true;
  281. else
  282. removeXmlSerializerImporter = true; // specifying datacontract will explicitly remove the Xml importer
  283. // if this parameter is not set we will simply use indigo defaults
  284. }
  285. ServiceEndpoint endpoint = null;
  286. ServiceEndpointCollection serviceEndpointsRetrieved = null;
  287. WsdlImporter importer;
  288. try
  289. {
  290. MetadataSet metadataSet = resolver.GetMetadata(mexEndpointAddress);
  291. if (useXmlSerializer)
  292. importer = CreateXmlSerializerImporter(metadataSet);
  293. else
  294. {
  295. if (removeXmlSerializerImporter)
  296. importer = CreateDataContractSerializerImporter(metadataSet);
  297. else
  298. importer = new WsdlImporter(metadataSet);
  299. }
  300. serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer);
  301. ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved);
  302. }
  303. catch (Exception e)
  304. {
  305. if (Fx.IsFatal(e))
  306. throw;
  307. if (UriSchemeSupportsDisco(mexEndpointAddress.Uri))
  308. {
  309. try
  310. {
  311. DiscoNS.DiscoveryClientProtocol discoClient = new DiscoNS.DiscoveryClientProtocol();
  312. discoClient.UseDefaultCredentials = true;
  313. discoClient.AllowAutoRedirect = true;
  314. discoClient.DiscoverAny(mexEndpointAddress.Uri.AbsoluteUri);
  315. discoClient.ResolveAll();
  316. MetadataSet metadataSet = new MetadataSet();
  317. foreach (object document in discoClient.Documents.Values)
  318. {
  319. AddDocumentToSet(metadataSet, document);
  320. }
  321. if (useXmlSerializer)
  322. importer = CreateXmlSerializerImporter(metadataSet);
  323. else
  324. {
  325. if (removeXmlSerializerImporter)
  326. importer = CreateDataContractSerializerImporter(metadataSet);
  327. else
  328. importer = new WsdlImporter(metadataSet);
  329. }
  330. serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer);
  331. ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved);
  332. }
  333. catch (Exception ex)
  334. {
  335. if (Fx.IsFatal(ex))
  336. throw;
  337. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, ex.Message)));
  338. }
  339. }
  340. else
  341. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, e.Message)));
  342. }
  343. if (serviceEndpointsRetrieved.Count == 0)
  344. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotFoundInRetreivedMex)));
  345. foreach (ServiceEndpoint retrievedEndpoint in serviceEndpointsRetrieved)
  346. {
  347. Binding bindingSelected = retrievedEndpoint.Binding;
  348. if ((bindingSelected.Name == binding) && (bindingSelected.Namespace == bindingNamespace))
  349. {
  350. endpoint = retrievedEndpoint;
  351. break;
  352. }
  353. }
  354. if (endpoint == null)
  355. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerNoneOfTheBindingMatchedTheSpecifiedBinding)));
  356. contractDescription = endpoint.Contract;
  357. this.serviceEndpoint = new ServiceEndpoint(contractDescription, endpoint.Binding, new EndpointAddress(new Uri(address), identity, (AddressHeaderCollection)null));
  358. ComPlusMexChannelBuilderTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexChannelBuilderLoaded,
  359. SR.TraceCodeComIntegrationMexChannelBuilderLoaded, endpoint.Contract, endpoint.Binding, address);
  360. }
  361. static bool UriSchemeSupportsDisco(Uri serviceUri)
  362. {
  363. return (serviceUri.Scheme == Uri.UriSchemeHttp) || (serviceUri.Scheme == Uri.UriSchemeHttps);
  364. }
  365. void AddDocumentToSet(MetadataSet metadataSet, object document)
  366. {
  367. WsdlNS.ServiceDescription wsdl = document as WsdlNS.ServiceDescription;
  368. XmlSchema schema = document as XmlSchema;
  369. XmlElement xmlDoc = document as XmlElement;
  370. if (wsdl != null)
  371. {
  372. metadataSet.MetadataSections.Add(MetadataSection.CreateFromServiceDescription(wsdl));
  373. }
  374. else if (schema != null)
  375. {
  376. metadataSet.MetadataSections.Add(MetadataSection.CreateFromSchema(schema));
  377. }
  378. else if (xmlDoc != null && MetadataSection.IsPolicyElement(xmlDoc))
  379. {
  380. metadataSet.MetadataSections.Add(MetadataSection.CreateFromPolicy(xmlDoc, null));
  381. }
  382. else
  383. {
  384. MetadataSection mexDoc = new MetadataSection();
  385. mexDoc.Metadata = document;
  386. metadataSet.MetadataSections.Add(mexDoc);
  387. }
  388. }
  389. public WsdlImporter CreateDataContractSerializerImporter(MetadataSet metaData)
  390. {
  391. Collection<IWsdlImportExtension> wsdlImportExtensions = ConfigNS.ClientSection.GetSection().Metadata.LoadWsdlImportExtensions();
  392. for (int i = 0; i < wsdlImportExtensions.Count; i++)
  393. {
  394. if (wsdlImportExtensions[i].GetType() == typeof(XmlSerializerMessageContractImporter))
  395. wsdlImportExtensions.RemoveAt(i);
  396. }
  397. WsdlImporter importer = new WsdlImporter(metaData, null, wsdlImportExtensions);
  398. return importer;
  399. }
  400. public WsdlImporter CreateXmlSerializerImporter(MetadataSet metaData)
  401. {
  402. Collection<IWsdlImportExtension> wsdlImportExtensions = ConfigNS.ClientSection.GetSection().Metadata.LoadWsdlImportExtensions();
  403. for (int i = 0; i < wsdlImportExtensions.Count; i++)
  404. {
  405. if (wsdlImportExtensions[i].GetType() == typeof(DataContractSerializerMessageContractImporter))
  406. wsdlImportExtensions.RemoveAt(i);
  407. }
  408. WsdlImporter importer = new WsdlImporter(metaData, null, wsdlImportExtensions);
  409. return importer;
  410. }
  411. ServiceEndpointCollection ImportWsdlPortType(XmlQualifiedName portTypeQName, WsdlImporter importer)
  412. {
  413. foreach (WsdlNS.ServiceDescription wsdl in importer.WsdlDocuments)
  414. {
  415. if (wsdl.TargetNamespace == portTypeQName.Namespace)
  416. {
  417. WsdlNS.PortType wsdlPortType = wsdl.PortTypes[portTypeQName.Name];
  418. if (wsdlPortType != null)
  419. {
  420. ServiceEndpointCollection endpoints = importer.ImportEndpoints(wsdlPortType);
  421. return endpoints;
  422. }
  423. }
  424. }
  425. return new ServiceEndpointCollection();
  426. }
  427. ComProxy IProxyCreator.CreateProxy(IntPtr outer, ref Guid riid)
  428. {
  429. IntPtr inner = IntPtr.Zero;
  430. if (riid != InterfaceID.idIDispatch)
  431. throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidCastException(SR.GetString(SR.NoInterface, riid)));
  432. if (contractDescription == null)
  433. {
  434. throw Fx.AssertAndThrow("ContractDescription should not be null at this point");
  435. }
  436. return DispatchProxy.Create(outer, contractDescription, this);
  437. }
  438. bool IProxyCreator.SupportsErrorInfo(ref Guid riid)
  439. {
  440. if (riid != InterfaceID.idIDispatch)
  441. return false;
  442. else
  443. return true;
  444. }
  445. bool IProxyCreator.SupportsDispatch()
  446. {
  447. return true;
  448. }
  449. bool IProxyCreator.SupportsIntrinsics()
  450. {
  451. return true;
  452. }
  453. }
  454. }