private void DoMex() { string str; string str2; string str3; string str4; string str5; string str6; string str7; string str8; string str9 = null; string str10 = null; string str11 = null; string str12 = null; string str13 = null; string str14 = null; string str15 = null; EndpointIdentity identity = null; EndpointIdentity identity2 = null; WsdlImporter importer; this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out str4); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out str5); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out str7); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out str6); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexAddress, out str); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBinding, out str2); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBindingConfiguration, out str3); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Address, out str8); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.SpnIdentity, out str9); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.UpnIdentity, out str10); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.DnsIdentity, out str11); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexSpnIdentity, out str12); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexUpnIdentity, out str13); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexDnsIdentity, out str14); this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Serializer, out str15); if (string.IsNullOrEmpty(str)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerMexAddressNotSpecified"))); } if (!string.IsNullOrEmpty(str12)) { if (!string.IsNullOrEmpty(str13) || !string.IsNullOrEmpty(str14)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentityForMex"))); } identity2 = EndpointIdentity.CreateSpnIdentity(str12); } else if (!string.IsNullOrEmpty(str13)) { if (!string.IsNullOrEmpty(str12) || !string.IsNullOrEmpty(str14)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentityForMex"))); } identity2 = EndpointIdentity.CreateUpnIdentity(str13); } else if (!string.IsNullOrEmpty(str14)) { if (!string.IsNullOrEmpty(str12) || !string.IsNullOrEmpty(str13)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentityForMex"))); } identity2 = EndpointIdentity.CreateDnsIdentity(str14); } else { identity2 = null; } if (string.IsNullOrEmpty(str8)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerAddressNotSpecified"))); } if (string.IsNullOrEmpty(str4)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerContractNotSpecified"))); } if (string.IsNullOrEmpty(str6)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerBindingNotSpecified"))); } if (string.IsNullOrEmpty(str7)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerBindingNamespacetNotSpecified"))); } if (!string.IsNullOrEmpty(str9)) { if (!string.IsNullOrEmpty(str10) || !string.IsNullOrEmpty(str11)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity"))); } identity = EndpointIdentity.CreateSpnIdentity(str9); } else if (!string.IsNullOrEmpty(str10)) { if (!string.IsNullOrEmpty(str9) || !string.IsNullOrEmpty(str11)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity"))); } identity = EndpointIdentity.CreateUpnIdentity(str10); } else if (!string.IsNullOrEmpty(str11)) { if (!string.IsNullOrEmpty(str9) || !string.IsNullOrEmpty(str10)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity"))); } identity = EndpointIdentity.CreateDnsIdentity(str11); } else { identity = null; } MetadataExchangeClient client = null; EndpointAddress address = new EndpointAddress(new Uri(str), identity2, new AddressHeader[0]); if (!string.IsNullOrEmpty(str2)) { System.ServiceModel.Channels.Binding mexBinding = null; try { mexBinding = ConfigLoader.LookupBinding(str2, str3); } catch (ConfigurationErrorsException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MexBindingNotFoundInConfig", new object[] { str2 }))); } if (mexBinding == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MexBindingNotFoundInConfig", new object[] { str2 }))); } client = new MetadataExchangeClient(mexBinding); } else { if (!string.IsNullOrEmpty(str3)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerMexBindingSectionNameNotSpecified"))); } client = new MetadataExchangeClient(address); } if (identity2 != null) { client.SoapCredentials.Windows.AllowNtlm = false; } bool flag = false; if (!string.IsNullOrEmpty(str15)) { if (("xml" != str15) && ("datacontract" != str15)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorectSerializer"))); } if ("xml" == str15) { this.useXmlSerializer = true; } else { flag = true; } } ServiceEndpoint endpoint = null; ServiceEndpointCollection serviceEndpointsRetrieved = null; try { MetadataSet metadata = client.GetMetadata(address); if (this.useXmlSerializer) { importer = this.CreateXmlSerializerImporter(metadata); } else if (flag) { importer = this.CreateDataContractSerializerImporter(metadata); } else { importer = new WsdlImporter(metadata); } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(str4, str5), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, 0x50024, "TraceCodeComIntegrationMexMonikerMetadataExchangeComplete", serviceEndpointsRetrieved); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } if (UriSchemeSupportsDisco(address.Uri)) { try { DiscoveryClientProtocol protocol = new DiscoveryClientProtocol { UseDefaultCredentials = true, AllowAutoRedirect = true }; protocol.DiscoverAny(address.Uri.AbsoluteUri); protocol.ResolveAll(); MetadataSet metadataSet = new MetadataSet(); foreach (object obj2 in protocol.Documents.Values) { this.AddDocumentToSet(metadataSet, obj2); } if (this.useXmlSerializer) { importer = this.CreateXmlSerializerImporter(metadataSet); } else if (flag) { importer = this.CreateDataContractSerializerImporter(metadataSet); } else { importer = new WsdlImporter(metadataSet); } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(str4, str5), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, 0x50024, "TraceCodeComIntegrationMexMonikerMetadataExchangeComplete", serviceEndpointsRetrieved); goto Label_0634; } catch (Exception exception2) { if (Fx.IsFatal(exception2)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerFailedToDoMexRetrieve", new object[] { exception2.Message }))); } } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerFailedToDoMexRetrieve", new object[] { exception.Message }))); } Label_0634: if (serviceEndpointsRetrieved.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerContractNotFoundInRetreivedMex"))); } foreach (ServiceEndpoint endpoint2 in serviceEndpointsRetrieved) { System.ServiceModel.Channels.Binding binding = endpoint2.Binding; if ((binding.Name == str6) && (binding.Namespace == str7)) { endpoint = endpoint2; break; } } if (endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerNoneOfTheBindingMatchedTheSpecifiedBinding"))); } this.contractDescription = endpoint.Contract; this.serviceEndpoint = new ServiceEndpoint(this.contractDescription, endpoint.Binding, new EndpointAddress(new Uri(str8), identity, null)); ComPlusMexChannelBuilderTrace.Trace(TraceEventType.Verbose, 0x50025, "TraceCodeComIntegrationMexChannelBuilderLoaded", endpoint.Contract, endpoint.Binding, str8); }
private void DoMex() { string mexAddress; string mexBindingSectionName; string mexBindingConfiguration; string contract; string contractNamespace; string binding; string bindingNamespace; string address; string spnIdentity = null; string upnIdentity = null; string dnsIdentity = null; string mexSpnIdentity = null; string mexUpnIdentity = null; string mexDnsIdentity = null; string serializer = null; EndpointIdentity identity = null; EndpointIdentity mexIdentity = null; propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out contract); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out contractNamespace); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out bindingNamespace); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out binding); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexAddress, out mexAddress); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBinding, out mexBindingSectionName); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexBindingConfiguration, out mexBindingConfiguration); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Address, out address); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.SpnIdentity, out spnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.UpnIdentity, out upnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.DnsIdentity, out dnsIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexSpnIdentity, out mexSpnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexUpnIdentity, out mexUpnIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.MexDnsIdentity, out mexDnsIdentity); propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Serializer, out serializer); if (string.IsNullOrEmpty(mexAddress)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexAddressNotSpecified))); } if (!string.IsNullOrEmpty(mexSpnIdentity)) { if ((!string.IsNullOrEmpty(mexUpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateSpnIdentity(mexSpnIdentity); } else if (!string.IsNullOrEmpty(mexUpnIdentity)) { if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexDnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateUpnIdentity(mexUpnIdentity); } else if (!string.IsNullOrEmpty(mexDnsIdentity)) { if ((!string.IsNullOrEmpty(mexSpnIdentity)) || (!string.IsNullOrEmpty(mexUpnIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentityForMex))); } mexIdentity = EndpointIdentity.CreateDnsIdentity(mexDnsIdentity); } else { mexIdentity = null; } if (string.IsNullOrEmpty(address)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerAddressNotSpecified))); } if (string.IsNullOrEmpty(contract)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotSpecified))); } if (string.IsNullOrEmpty(binding)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNotSpecified))); } if (string.IsNullOrEmpty(bindingNamespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerBindingNamespacetNotSpecified))); } if (!string.IsNullOrEmpty(spnIdentity)) { if ((!string.IsNullOrEmpty(upnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateSpnIdentity(spnIdentity); } else if (!string.IsNullOrEmpty(upnIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(dnsIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateUpnIdentity(upnIdentity); } else if (!string.IsNullOrEmpty(dnsIdentity)) { if ((!string.IsNullOrEmpty(spnIdentity)) || (!string.IsNullOrEmpty(upnIdentity))) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorrectServerIdentity))); } identity = EndpointIdentity.CreateDnsIdentity(dnsIdentity); } else { identity = null; } MetadataExchangeClient resolver = null; EndpointAddress mexEndpointAddress = new EndpointAddress(new Uri(mexAddress), mexIdentity); if (!string.IsNullOrEmpty(mexBindingSectionName)) { Binding mexBinding = null; try { mexBinding = ConfigLoader.LookupBinding(mexBindingSectionName, mexBindingConfiguration); } catch (System.Configuration.ConfigurationErrorsException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName))); } if (null == mexBinding) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MexBindingNotFoundInConfig, mexBindingSectionName))); } resolver = new MetadataExchangeClient(mexBinding); } else if (string.IsNullOrEmpty(mexBindingConfiguration)) { resolver = new MetadataExchangeClient(mexEndpointAddress); } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerMexBindingSectionNameNotSpecified))); } if (null != mexIdentity) { // To disable AllowNtlm warning. #pragma warning disable 618 resolver.SoapCredentials.Windows.AllowNtlm = false; #pragma warning restore 618 } bool removeXmlSerializerImporter = false; if (!String.IsNullOrEmpty(serializer)) { if ("xml" != serializer && "datacontract" != serializer) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerIncorectSerializer))); } if ("xml" == serializer) { useXmlSerializer = true; } else { removeXmlSerializerImporter = true; // specifying datacontract will explicitly remove the Xml importer } // if this parameter is not set we will simply use indigo defaults } ServiceEndpoint endpoint = null; ServiceEndpointCollection serviceEndpointsRetrieved = null; WsdlImporter importer; try { MetadataSet metadataSet = resolver.GetMetadata(mexEndpointAddress); if (useXmlSerializer) { importer = CreateXmlSerializerImporter(metadataSet); } else { if (removeXmlSerializerImporter) { importer = CreateDataContractSerializerImporter(metadataSet); } else { importer = new WsdlImporter(metadataSet); } } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (UriSchemeSupportsDisco(mexEndpointAddress.Uri)) { try { DiscoNS.DiscoveryClientProtocol discoClient = new DiscoNS.DiscoveryClientProtocol(); discoClient.UseDefaultCredentials = true; discoClient.AllowAutoRedirect = true; discoClient.DiscoverAny(mexEndpointAddress.Uri.AbsoluteUri); discoClient.ResolveAll(); MetadataSet metadataSet = new MetadataSet(); foreach (object document in discoClient.Documents.Values) { AddDocumentToSet(metadataSet, document); } if (useXmlSerializer) { importer = CreateXmlSerializerImporter(metadataSet); } else { if (removeXmlSerializerImporter) { importer = CreateDataContractSerializerImporter(metadataSet); } else { importer = new WsdlImporter(metadataSet); } } serviceEndpointsRetrieved = this.ImportWsdlPortType(new XmlQualifiedName(contract, contractNamespace), importer); ComPlusMexChannelBuilderMexCompleteTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexMonikerMetadataExchangeComplete, SR.TraceCodeComIntegrationMexMonikerMetadataExchangeComplete, serviceEndpointsRetrieved); } catch (Exception ex) { if (Fx.IsFatal(ex)) { throw; } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, ex.Message))); } } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerFailedToDoMexRetrieve, e.Message))); } } if (serviceEndpointsRetrieved.Count == 0) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerContractNotFoundInRetreivedMex))); } foreach (ServiceEndpoint retrievedEndpoint in serviceEndpointsRetrieved) { Binding bindingSelected = retrievedEndpoint.Binding; if ((bindingSelected.Name == binding) && (bindingSelected.Namespace == bindingNamespace)) { endpoint = retrievedEndpoint; break; } } if (endpoint == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.MonikerNoneOfTheBindingMatchedTheSpecifiedBinding))); } contractDescription = endpoint.Contract; this.serviceEndpoint = new ServiceEndpoint(contractDescription, endpoint.Binding, new EndpointAddress(new Uri(address), identity, (AddressHeaderCollection)null)); ComPlusMexChannelBuilderTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationMexChannelBuilderLoaded, SR.TraceCodeComIntegrationMexChannelBuilderLoaded, endpoint.Contract, endpoint.Binding, address); }