コード例 #1
0
        private void ProcessWsdl()
        {
            string           str;
            string           str2;
            string           str3;
            string           str4;
            string           str5            = null;
            string           str6            = null;
            string           str7            = null;
            EndpointIdentity identity        = null;
            string           str8            = null;
            string           targetNamespace = null;
            string           str10           = null;

            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Wsdl, out str);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out str2);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out str3);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Address, out str4);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.SpnIdentity, out str5);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.UpnIdentity, out str6);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.DnsIdentity, out str7);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Serializer, out str8);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out str10);
            this.propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out targetNamespace);
            if (string.IsNullOrEmpty(str))
            {
                throw Fx.AssertAndThrow("Wsdl should not be null at this point");
            }
            if ((string.IsNullOrEmpty(str2) || string.IsNullOrEmpty(str3)) || string.IsNullOrEmpty(str4))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("ContractBindingAddressCannotBeNull")));
            }
            if (!string.IsNullOrEmpty(str5))
            {
                if (!string.IsNullOrEmpty(str6) || !string.IsNullOrEmpty(str7))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity")));
                }
                identity = EndpointIdentity.CreateSpnIdentity(str5);
            }
            else if (!string.IsNullOrEmpty(str6))
            {
                if (!string.IsNullOrEmpty(str5) || !string.IsNullOrEmpty(str7))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity")));
                }
                identity = EndpointIdentity.CreateUpnIdentity(str6);
            }
            else if (!string.IsNullOrEmpty(str7))
            {
                if (!string.IsNullOrEmpty(str5) || !string.IsNullOrEmpty(str6))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorrectServerIdentity")));
                }
                identity = EndpointIdentity.CreateDnsIdentity(str7);
            }
            else
            {
                identity = null;
            }
            bool flag = false;

            if (!string.IsNullOrEmpty(str8))
            {
                if (("xml" != str8) && ("datacontract" != str8))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("MonikerIncorectSerializer")));
                }
                if ("xml" == str8)
                {
                    this.useXmlSerializer = true;
                }
                else
                {
                    flag = true;
                }
            }
            TextReader textReader = new StringReader(str);

            try
            {
                WsdlImporter importer;
                System.Web.Services.Description.ServiceDescription serviceDescription = System.Web.Services.Description.ServiceDescription.Read(textReader);
                if (string.IsNullOrEmpty(targetNamespace))
                {
                    targetNamespace = serviceDescription.TargetNamespace;
                }
                if (string.IsNullOrEmpty(str10))
                {
                    str10 = serviceDescription.TargetNamespace;
                }
                ServiceDescriptionCollection wsdlDocuments = new ServiceDescriptionCollection();
                wsdlDocuments.Add(serviceDescription);
                XmlSchemaSet xmlSchemas = new XmlSchemaSet();
                foreach (System.Xml.Schema.XmlSchema schema in serviceDescription.Types.Schemas)
                {
                    xmlSchemas.Add(schema);
                }
                MetadataSet metaData = new MetadataSet(WsdlImporter.CreateMetadataDocuments(wsdlDocuments, xmlSchemas, null));
                if (this.useXmlSerializer)
                {
                    importer = this.CreateXmlSerializerImporter(metaData);
                }
                else if (flag)
                {
                    importer = this.CreateDataContractSerializerImporter(metaData);
                }
                else
                {
                    importer = new WsdlImporter(metaData);
                }
                XmlQualifiedName name     = new XmlQualifiedName(str2, targetNamespace);
                XmlQualifiedName name2    = new XmlQualifiedName(str3, str10);
                PortType         portType = wsdlDocuments.GetPortType(name);
                this.contractDescription = importer.ImportContract(portType);
                System.Web.Services.Description.Binding wsdlBinding = wsdlDocuments.GetBinding(name2);
                System.ServiceModel.Channels.Binding    binding     = importer.ImportBinding(wsdlBinding);
                EndpointAddress address = new EndpointAddress(new Uri(str4), identity, null);
                this.serviceEndpoint = new ServiceEndpoint(this.contractDescription, binding, address);
                ComPlusWsdlChannelBuilderTrace.Trace(TraceEventType.Verbose, 0x5001d, "TraceCodeComIntegrationWsdlChannelBuilderLoaded", name2, name, serviceDescription, this.contractDescription, binding, serviceDescription.Types.Schemas);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(System.ServiceModel.SR.GetString("FailedImportOfWsdl", new object[] { exception.Message })));
            }
            finally
            {
                IDisposable disposable = textReader;
                disposable.Dispose();
            }
        }
コード例 #2
0
        private void ProcessWsdl()
        {
            string           wsdlText;
            string           portType;
            string           bindingName;
            string           address;
            string           spnIdentity       = null;
            string           upnIdentity       = null;
            string           dnsIdentity       = null;
            EndpointIdentity identity          = null;
            string           serializer        = null;
            string           contractNamespace = null;
            string           bindingNamespace  = null;

            propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Wsdl, out wsdlText);
            propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Contract, out portType);
            propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.Binding, out bindingName);
            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.Serializer, out serializer);
            propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.BindingNamespace, out bindingNamespace);
            propertyTable.TryGetValue(MonikerHelper.MonikerAttribute.ContractNamespace, out contractNamespace);

            if (string.IsNullOrEmpty(wsdlText))
            {
                throw Fx.AssertAndThrow("Wsdl should not be null at this point");
            }
            if (string.IsNullOrEmpty(portType) || string.IsNullOrEmpty(bindingName) || string.IsNullOrEmpty(address))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.ContractBindingAddressCannotBeNull)));
            }

            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;
            }

            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
            }

            TextReader reader = new StringReader(wsdlText);

            try
            {
                try
                {
                    WsdlNS.ServiceDescription wsdl = WsdlNS.ServiceDescription.Read(reader);

                    if (String.IsNullOrEmpty(contractNamespace))
                    {
                        contractNamespace = wsdl.TargetNamespace;
                    }

                    if (String.IsNullOrEmpty(bindingNamespace))
                    {
                        bindingNamespace = wsdl.TargetNamespace;
                    }

                    WsdlNS.ServiceDescriptionCollection wsdlDocs = new WsdlNS.ServiceDescriptionCollection();
                    wsdlDocs.Add(wsdl);
                    XmlSchemaSet schemas = new XmlSchemaSet();
                    foreach (XmlSchema schema in wsdl.Types.Schemas)
                    {
                        schemas.Add(schema);
                    }

                    MetadataSet  mds = new MetadataSet(WsdlImporter.CreateMetadataDocuments(wsdlDocs, schemas, null));
                    WsdlImporter importer;

                    if (useXmlSerializer)
                    {
                        importer = CreateXmlSerializerImporter(mds);
                    }
                    else
                    {
                        if (removeXmlSerializerImporter)
                        {
                            importer = CreateDataContractSerializerImporter(mds);
                        }
                        else
                        {
                            importer = new WsdlImporter(mds);
                        }
                    }

                    XmlQualifiedName contractQname = new XmlQualifiedName(portType, contractNamespace);
                    XmlQualifiedName bindingQname  = new XmlQualifiedName(bindingName, bindingNamespace);

                    WsdlNS.PortType wsdlPortType = wsdlDocs.GetPortType(contractQname);
                    contractDescription = importer.ImportContract(wsdlPortType);

                    WsdlNS.Binding wsdlBinding = wsdlDocs.GetBinding(bindingQname);
                    Binding        binding     = importer.ImportBinding(wsdlBinding);

                    EndpointAddress endpointAddress = new EndpointAddress(new Uri(address), identity, (AddressHeaderCollection)null);

                    serviceEndpoint = new ServiceEndpoint(contractDescription, binding, endpointAddress);

                    ComPlusWsdlChannelBuilderTrace.Trace(TraceEventType.Verbose, TraceCode.ComIntegrationWsdlChannelBuilderLoaded,
                                                         SR.TraceCodeComIntegrationWsdlChannelBuilderLoaded, bindingQname, contractQname, wsdl, contractDescription, binding, wsdl.Types.Schemas);
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }

                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new MonikerSyntaxException(SR.GetString(SR.FailedImportOfWsdl, e.Message)));
                }
            }
            finally
            {
                IDisposable disposee = reader;
                disposee.Dispose();
            }
        }