コード例 #1
0
		internal void OnServiceDescriptionAdded (ServiceDescription serviceDescription, string appSettingUrlKey, string appSettingBaseUrl)
		{
			serviceDescriptions.Add (serviceDescription);
			ImportInfo info = new ImportInfo (serviceDescription, appSettingUrlKey, appSettingBaseUrl);
			importInfo.Add (info);
			
			if (serviceDescription.Types != null)
				schemas.Add (serviceDescription.Types.Schemas);
		}
コード例 #2
0
		public static bool CheckConformance (WsiClaims claims, ServiceDescription service, BasicProfileViolationCollection violations)
		{
			ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
			col.Add (service);
			ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
			return Check (claims, ctx, col);
		}
コード例 #3
0
        public static bool CheckConformance(WsiProfiles claims, ServiceDescription service, BasicProfileViolationCollection violations)
        {
            ServiceDescriptionCollection col = new ServiceDescriptionCollection();

            col.Add(service);
            ConformanceCheckContext ctx = new ConformanceCheckContext(col, violations);

            return(Check(claims, ctx, col));
        }
コード例 #4
0
        public static bool CheckConformance(WsiProfiles claims, ServiceDescription description, BasicProfileViolationCollection violations)
        {
            if (description == null)
            {
                throw new ArgumentNullException("description");
            }
            ServiceDescriptionCollection descriptions = new ServiceDescriptionCollection();

            descriptions.Add(description);
            return(CheckConformance(claims, descriptions, violations));
        }
コード例 #5
0
		public static ServiceDescriptionCollection GetServiceDescriptions(DiscoveryClientProtocol protocol)
		{
			ServiceDescriptionCollection services = new ServiceDescriptionCollection();
			protocol.ResolveOneLevel();
		
			foreach (DictionaryEntry entry in protocol.References) {
				ContractReference contractRef = entry.Value as ContractReference;
				if (contractRef != null) {
					services.Add(contractRef.Contract);
				}
			}
			return services;
		}
 internal static void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions, StringCollection warnings)
 {
     ServiceDescription serviceDescription = document as ServiceDescription;
     if (serviceDescription != null)
     {
         descriptions.Add(serviceDescription);
     }
     else
     {
         XmlSchema schema = document as XmlSchema;
         if (schema != null)
         {
             schemas.Add(schema);
         }
     }
 }
コード例 #7
0
        internal static void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions, StringCollection warnings)
        {
            ServiceDescription serviceDescription = document as ServiceDescription;

            if (serviceDescription != null)
            {
                descriptions.Add(serviceDescription);
            }
            else
            {
                XmlSchema schema = document as XmlSchema;
                if (schema != null)
                {
                    schemas.Add(schema);
                }
            }
        }
コード例 #8
0
ファイル: SampleGenerator.cs プロジェクト: Zman0169/mono
		public static void Generate (ArrayList services, ArrayList schemas, string binOper, string protocol)
		{
			ServiceDescriptionCollection descCol = new ServiceDescriptionCollection ();
			foreach (ServiceDescription sd in services)
				descCol.Add (sd);
				
			XmlSchemas schemaCol;

			if (schemas.Count > 0) {
				schemaCol = new XmlSchemas ();
				foreach (XmlSchema sc in schemas)
					schemaCol.Add (sc);
			}
			else
				schemaCol = descCol[0].Types.Schemas;
				
			string oper, bin = null; 
			
			int i = binOper.IndexOf ('/');
			if (i != -1) {
				oper = binOper.Substring (i+1);
				bin = binOper.Substring (0,i);
			}
			else
				oper = binOper;
			
			ConsoleSampleGenerator sg = new ConsoleSampleGenerator (descCol, schemaCol);
			
			string req, resp;
			sg.GenerateMessages (oper, bin, protocol, out req, out resp);
			
			Console.WriteLine ();
			Console.WriteLine ("Sample request message:");
			Console.WriteLine ();
			Console.WriteLine (req);
			Console.WriteLine ();
			Console.WriteLine ("Sample response message:");
			Console.WriteLine ();
			Console.WriteLine (resp);
		}
コード例 #9
0
ファイル: Wsdl.cs プロジェクト: hdougie/webservicestudio2
 private void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions)
 {
     ServiceDescription serviceDescription = document as ServiceDescription;
     if (serviceDescription != null)
     {
         if (descriptions[serviceDescription.TargetNamespace] == null)
         {
             descriptions.Add(serviceDescription);
             StringWriter w = new StringWriter();
             XmlTextWriter writer = new XmlTextWriter(w);
             writer.Formatting = Formatting.Indented;
             serviceDescription.Write(writer);
             this.wsdls.Add(w.ToString());
         }
         else
         {
             this.CheckPoint(MessageType.Warning, string.Format(duplicateService, serviceDescription.TargetNamespace, path));
         }
     }
     else
     {
         XmlSchema schema = document as XmlSchema;
         if (schema != null)
         {
             if (schemas[schema.TargetNamespace] == null)
             {
                 schemas.Add(schema);
                 StringWriter writer3 = new StringWriter();
                 XmlTextWriter writer4 = new XmlTextWriter(writer3);
                 writer4.Formatting = Formatting.Indented;
                 schema.Write(writer4);
                 this.xsds.Add(writer3.ToString());
             }
             else
             {
                 this.CheckPoint(MessageType.Warning, string.Format(duplicateSchema, serviceDescription.TargetNamespace, path));
             }
         }
     }
 }
コード例 #10
0
ファイル: ConformanceChecker.cs プロジェクト: Tsalex71/mono-1
        public ConformanceCheckContext(WebReference webReference, BasicProfileViolationCollection violations)
        {
            this.webReference = webReference;
            this.violations   = violations;
            services          = new ServiceDescriptionCollection();

            foreach (object doc in webReference.Documents.Values)
            {
                if (doc is XmlSchema)
                {
                    schemas.Add((XmlSchema)doc);
                }
                else if (doc is ServiceDescription)
                {
                    ServiceDescription sd = (ServiceDescription)doc;
                    services.Add(sd);
                    if (sd.Types != null && sd.Types.Schemas != null)
                    {
                        schemas.Add(sd.Types.Schemas);
                    }
                }
            }
        }
コード例 #11
0
        void ImportBinding(ServiceDescription desc, Service service, TypeStubInfo typeInfo, string url, BindingInfo binfo)
        {
            port      = new Port();
            port.Name = portNames.AddUnique(binfo.Name, port);
            bool bindingFull = true;

            if (binfo.Namespace != desc.TargetNamespace)
            {
                if (binfo.Location == null || binfo.Location == string.Empty)
                {
                    ServiceDescription newDesc = new ServiceDescription();
                    newDesc.TargetNamespace = binfo.Namespace;
                    newDesc.Name            = binfo.Name;
                    bindingFull             = ImportBindingContent(newDesc, typeInfo, url, binfo);
                    if (bindingFull)
                    {
                        int id = ServiceDescriptions.Add(newDesc);
                        AddImport(desc, binfo.Namespace, GetWsdlUrl(url, id));
                    }
                }
                else
                {
                    AddImport(desc, binfo.Namespace, binfo.Location);
                    bindingFull = true;
                }
            }
            else
            {
                bindingFull = ImportBindingContent(desc, typeInfo, url, binfo);
            }

            if (bindingFull)
            {
                port.Binding = new XmlQualifiedName(binding.Name, binfo.Namespace);

                int    n    = 0;
                string name = binfo.Name;
                bool   found;
                do
                {
                    found = false;
                    foreach (Port p in service.Ports)
                    {
                        if (p.Name == name)
                        {
                            found = true; n++; name = binfo.Name + n; break;
                        }
                    }
                }while (found);
                port.Name = name;
                service.Ports.Add(port);
            }

#if NET_2_0
            if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.ConformsTo != WsiProfiles.None && String.IsNullOrEmpty(binfo.WebServiceBindingAttribute.Name))
            {
                BasicProfileViolationCollection violations = new BasicProfileViolationCollection();
                desc.Types.Schemas.Add(Schemas);
                ServiceDescriptionCollection col = new ServiceDescriptionCollection();
                col.Add(desc);
                ConformanceCheckContext ctx = new ConformanceCheckContext(col, violations);
                ctx.ServiceDescription = desc;
                ConformanceChecker[] checkers = WebServicesInteroperability.GetCheckers(binfo.WebServiceBindingAttribute.ConformsTo);
                foreach (ConformanceChecker checker in checkers)
                {
                    ctx.Checker = checker;
                    WebServicesInteroperability.Check(ctx, checker, binding);
                    if (violations.Count > 0)
                    {
                        throw new InvalidOperationException(violations [0].ToString());
                    }
                }
            }
#endif
        }
 public static bool CheckConformance(WsiProfiles claims, ServiceDescription description, BasicProfileViolationCollection violations)
 {
     if (description == null)
     {
         throw new ArgumentNullException("description");
     }
     ServiceDescriptionCollection descriptions = new ServiceDescriptionCollection();
     descriptions.Add(description);
     return CheckConformance(claims, descriptions, violations);
 }
コード例 #13
0
ファイル: WebReference.cs プロジェクト: Paccc/SharpDevelop
		ServiceDescriptionCollection GetServiceDescriptionCollection(DiscoveryClientProtocol protocol)
		{
			ServiceDescriptionCollection services = new ServiceDescriptionCollection();
			foreach (DictionaryEntry entry in protocol.References) {
				ContractReference contractRef = entry.Value as ContractReference;
				DiscoveryDocumentReference discoveryRef = entry.Value as DiscoveryDocumentReference;
				if (contractRef != null) {
					services.Add(contractRef.Contract);
				}
			}
			return services;
		}
コード例 #14
0
		public WsdlImporter (
			MetadataSet metadata,
			IEnumerable<IPolicyImportExtension> policyImportExtensions,
			IEnumerable<IWsdlImportExtension> wsdlImportExtensions)
			: base (policyImportExtensions)
		{
			if (metadata == null)
				throw new ArgumentNullException ("metadata");
			
			if (wsdlImportExtensions == null) {
				wsdl_extensions = new KeyedByTypeCollection<IWsdlImportExtension> ();

				wsdl_extensions.Add (new StandardBindingImporter ());
				wsdl_extensions.Add (new TransportBindingElementImporter ());
				//wsdl_extensions.Add (new MessageEncodingBindingElementImporter ());
				wsdl_extensions.Add (new XmlSerializerMessageContractImporter ());
				wsdl_extensions.Add (new DataContractSerializerMessageContractImporter ());
			} else {
				wsdl_extensions = new KeyedByTypeCollection<IWsdlImportExtension> (wsdlImportExtensions);
			}

			this.metadata = metadata;
			this.wsdl_documents = new ServiceDescriptionCollection ();
			this.xmlschemas = new XmlSchemaSet ();
			this.policies = new List<XmlElement> ();

			foreach (MetadataSection ms in metadata.MetadataSections) {
				if (ms.Dialect == MetadataSection.ServiceDescriptionDialect &&
					ms.Metadata.GetType () == typeof (WSServiceDescription))
					wsdl_documents.Add ((WSServiceDescription) ms.Metadata);
				else
				if (ms.Dialect == MetadataSection.XmlSchemaDialect &&
					ms.Metadata.GetType () == typeof (XmlSchema))
					xmlschemas.Add ((XmlSchema) ms.Metadata);
			}
		}
コード例 #15
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();
            }
        }
コード例 #16
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();
            }
        }
コード例 #17
0
ファイル: GenSampleData.cs プロジェクト: umabiel/WsdlUI
        public model.WebSvcMethodContainer GenerateSampleData()
        {
            Dictionary<string, model.WebSvcMethod> results = new Dictionary<string, model.WebSvcMethod>();

            List<string> methodList = GetMethodList();

            foreach (string method in methodList) {
                ServiceDescriptionCollection descCol = new ServiceDescriptionCollection();
                foreach (ServiceDescription sd in _descriptions) {
                    descCol.Add(sd);
                }

                XmlSchemas schemaCol;
                if (_schemas.Count > 0) {
                    schemaCol = new XmlSchemas();
                    foreach (XmlSchema sc in _schemas) {
                        schemaCol.Add(sc);
                    }
                }
                else {
                    schemaCol = descCol[0].Types.Schemas;
                }

                string req;
                string resp;

                SampleGeneratorWebSvc sg = new SampleGeneratorWebSvc(descCol, schemaCol);
                sg.GenerateMessages(method, null, "Soap", out req, out resp);

                int indexOfReqMsg = req.IndexOf(@"<soap:Envelope");
                string reqHeaderMsg = req.Substring(0, indexOfReqMsg);
                string sampleReqMsg = req.Substring(indexOfReqMsg);

                int indexOfRespMsg = resp.IndexOf(@"<soap:Envelope");
                string respHeaderMsg = resp.Substring(0, indexOfRespMsg);
                string sampleRespMsg = resp.Substring(indexOfRespMsg);

                string[] reqHeaderLines = reqHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string soapAction = GetHeader(reqHeaderLines, "SOAPAction:");
                string reqContentType = GetHeader(reqHeaderLines, "Content-Type:");

                string[] respHeaderLines = respHeaderMsg.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                string respContentType = GetHeader(respHeaderLines, "Content-Type:");

                model.WebSvcMessageRequest messageRequest = new model.WebSvcMessageRequest();
                messageRequest.Body = sampleReqMsg;
                messageRequest.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE] = reqContentType;
                messageRequest.Headers[model.WebSvcMessageRequest.HEADER_NAME_SOAP_ACTION] = soapAction;

                model.WebSvcMessageResponse messageResponse = new model.WebSvcMessageResponse();
                messageResponse.Body = sampleRespMsg;
                messageResponse.Headers[model.WebSvcMessage.HEADER_NAME_CONTENT_TYPE] = respContentType;

                model.WebSvcMethod webMethod = new model.WebSvcMethod(method, _serviceURI) {
                    Request = messageRequest,
                    Response = messageResponse
                };

                results[method] = webMethod;
            }

            return new model.WebSvcMethodContainer(results);
        }
コード例 #18
0
 private void AddDocument(string path, object document, XmlSchemas schemas,
                          ServiceDescriptionCollection descriptions)
 {
     ServiceDescription description1 = document as ServiceDescription;
     if (description1 != null)
     {
         if (descriptions[description1.TargetNamespace] == null)
         {
             descriptions.Add(description1);
             StringWriter writer1 = new StringWriter();
             XmlTextWriter writer2 = new XmlTextWriter(writer1);
             writer2.Formatting = Formatting.Indented;
             description1.Write(writer2);
             wsdls.Add(writer1.ToString());
         }
         else
         {
             CheckPoint(MessageType.Warning, string.Format(duplicateService, description1.TargetNamespace, path));
         }
     }
     else
     {
         XmlSchema schema1 = document as XmlSchema;
         if (schema1 != null)
         {
             if (schemas[schema1.TargetNamespace] == null)
             {
                 schemas.Add(schema1);
                 StringWriter writer3 = new StringWriter();
                 XmlTextWriter writer4 = new XmlTextWriter(writer3);
                 writer4.Formatting = Formatting.Indented;
                 schema1.Write(writer4);
                 xsds.Add(writer3.ToString());
             }
             else
             {
                 CheckPoint(MessageType.Warning,
                            string.Format(duplicateSchema, description1.TargetNamespace, path));
             }
         }
     }
 }
 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();
     }
 }
コード例 #20
0
ファイル: MFMetadataExporter.cs プロジェクト: prabby/miniclr
        /// <summary>
        /// Given an assembly, use reflection to parse the assemblies module(s) and gerenate a wsdl.
        /// </summary>
        /// <param name="assemblyName">A String containing the path/name of an assembly to process.</param>
        /// <param name="referencePath">A string containing a path used to load refernced assemblies not found in the Gac.</param>
        /// <param name="wsdlFilenameOverride">A string containing a specified wsdl filename.</param>
        /// <param name="contractName">A string containing the name of a specific service contract in the assembly to process.</param>
        /// <param name="destinationPath">A string containing the name of a directory where generated files are created.</param>
        /// <param name="generateSourceFiles">If true generate DPWS source files.</param>
        public void ParseCode(string assemblyName, string referencePath, string wsdlFilenameOverride, string contractName, string destinationPath, bool generateSourceFiles)
        {
            m_assemblyRefPath = referencePath;
            AppDomain domain = AppDomain.CurrentDomain;
            domain.AssemblyResolve += new ResolveEventHandler(domain_AssemblyResolve);

            if (assemblyName == null)
                throw new ArgumentNullException("assemblyName", "Must not be null");

            // If a specific contract is specified only process it
            bool contractFound = false;

            // Load the assembly
            Assembly asm = Assembly.LoadFrom(assemblyName);
            Module[] mods = asm.GetLoadedModules();
            ServiceDescriptionCollection serviceDescriptions = new ServiceDescriptionCollection();
            List<Type> m_processedTypes = new List<Type>();
            bool m_includeBinding = true;

            // Iterate the colleciton of modules in the assembly
            foreach (Module mod in mods)
            {
                Logger.WriteLine("Module name = " + mod.Name, LogLevel.Verbose);
                // Iterate the types in a module looking for types with key attributes
                Type[] types = mod.GetTypes();
                foreach (Type t in types)
                {
                    bool hasPolicy = false;
                    bool hasEvents = false;
                    bool hasOptimizedMimePolicy = false;

                    if (m_processedTypes.Contains(t))
                        continue;

                    // Inintialize a service description used to store the type information if key types are found
                    ServiceDescription serviceDesc = null;
                    PortType portType = null;
                    
                    // For a type iterate an optional list of attributes looking for ServiceContract or DataContract attributes
                    object[] customAttribs = t.GetCustomAttributes(true);
                    for (int i = 0; i < customAttribs.Length; ++i)
                    {
                        // Look for ServiceContract and DataContract attributes
                        Attribute attrib = (Attribute)customAttribs[i];
                        switch (((Type)attrib.TypeId).Name)
                        {
                            case "PolicyAssertionAttribute":
                            case "PolicyAssertion":
                                
                                // Set policy flag
                                hasPolicy = true;

                                // If an Mtom policy assertinon attribute is found set the mtom flag
                                string policy = (string)attrib.GetType().GetProperty("Name", typeof(string)).GetValue(attrib, null);
                                if (policy != null && policy == "OptimizedMimeSerialization")
                                    hasOptimizedMimePolicy = true;
                                break;
                            case "ServiceContractAttribute":
                            case "ServiceContract":

                                // This flag enforces processing of the specified service contract only if specified
                                if (contractFound == true)
                                    break;

                                // If the specified contract is found set the flag    
                                if (contractName != null && contractName == t.Name)
                                    contractFound = true;

                                // If a matching service description is found, append this contract to it else
                                // create a new service description and add it to the service description collection
                                if (serviceDesc == null)
                                {
                                    // If a service description with the same namespace exists append this types information
                                    string typeNamespace = (string)attrib.GetType().GetProperty("Namespace", typeof(string)).GetValue(attrib, null);
                                    typeNamespace = typeNamespace == null ? FixupNamespace(t.Namespace) : typeNamespace;
                                    if ((serviceDesc = FindServiceDescription(typeNamespace, serviceDescriptions)) == null)
                                    {
                                        serviceDesc = new ServiceDescription();
                                        serviceDesc.TargetNamespace = typeNamespace;
                                        serviceDescriptions.Add(serviceDesc);
                                    }
                                }

                                // Process contract type
                                if ((portType = ProcessServiceContract(t, false, serviceDesc)) == null)
                                    throw new Exception("Contract " + t.FullName + " failed to process.");
                                else
                                {
                                    // Set the port type name
                                    portType.Name = (string)attrib.GetType().GetProperty("Name", typeof(string)).GetValue(attrib, null);
                                    if (portType.Name == null)
                                        portType.Name = (t.IsInterface && t.Name[0] == 'I') ? t.Name.Substring(1) : t.Name;

                                    // The the port type to the service description
                                    serviceDesc.PortTypes.Add(portType);
                                    serviceDesc.Name = serviceDesc.Name == null ? portType.Name : serviceDesc.Name;
                                }

                                // Check to see if a callback contract is specified by the service contract attribute
                                // If the contract has an associated callback contract process it
                                Type callbackType = (Type)attrib.GetType().GetProperty("CallbackContract").GetValue(attrib, null);
                                if (callbackType != null)
                                {
                                    // Process callback type
                                    PortType callbackPortType = new PortType();
                                    if ((callbackPortType = ProcessServiceContract(callbackType, true, serviceDesc)) == null)
                                        throw new Exception("Callback contract " + callbackType.Name + " failed to process.");
                                    else
                                    {
                                        // Add callback operations to existing contract porttype operations collection
                                        foreach (Operation operation in callbackPortType.Operations)
                                            portType.Operations.Add(operation);
                                    }

                                    // Set eventing policy indicator
                                    hasEvents = true;

                                    // Add callback type to list of processed types
                                    m_processedTypes.Add(callbackType);
                                }

                                // Add binding if requested
                                if (m_includeBinding)
                                    serviceDesc.Bindings.Add(CreateBinding(portType));

                                // Add contract type to list of processed types
                                m_processedTypes.Add(t);

                                break;
                            case "DataContractAttribute":
                            case "DataContract":

                                string dataTypeNamespace = (string)attrib.GetType().GetProperty("Namespace", typeof(string)).GetValue(attrib, null);
                                dataTypeNamespace = dataTypeNamespace == null ? FixupNamespace(t.Namespace) : dataTypeNamespace;

                                // If a service contract is found set the service description
                                if (serviceDesc == null)
                                {
                                    // If a service description with the same namespace exists append this types information
                                    if ((serviceDesc = FindServiceDescription(dataTypeNamespace, serviceDescriptions)) == null)
                                    {
                                        serviceDesc = new ServiceDescription();
                                        serviceDescriptions.Add(serviceDesc);
                                        serviceDesc.TargetNamespace = dataTypeNamespace;
                                    }
                                }

                                ProcessDataContract(t, dataTypeNamespace, serviceDesc);
                                break;
                            default:
                                break;
                        }
                    }

                    // Add Policy element to service description
                    if (hasPolicy)
                        AddPolicyBindingElement(serviceDesc, hasEvents, hasOptimizedMimePolicy);
                }
            }

            // Generate Wsdls from service descriptions collection
            m_codeGen.GenerateWsdls(serviceDescriptions, wsdlFilenameOverride, destinationPath);
        }
コード例 #21
0
ファイル: ConformanceChecker.cs プロジェクト: nobled/mono
		public ConformanceCheckContext (WebReference webReference, BasicProfileViolationCollection violations)
		{
			this.webReference = webReference;
			this.violations = violations;
			services = new ServiceDescriptionCollection ();
			
			foreach (object doc in webReference.Documents.Values) 
			{
				if (doc is XmlSchema)
					schemas.Add ((XmlSchema)doc);
				else if (doc is ServiceDescription) {
					ServiceDescription sd = (ServiceDescription) doc;
					services.Add (sd);
					if (sd.Types != null && sd.Types.Schemas != null)
						schemas.Add (sd.Types.Schemas);
				}
			}
		}
コード例 #22
0
ファイル: WsdlImporter.cs プロジェクト: nlhepler/mono
		public WsdlImporter (
			MetadataSet metadata,
			IEnumerable<IPolicyImportExtension> policyImportExtensions,
			IEnumerable<IWsdlImportExtension> wsdlImportExtensions)
			: base (policyImportExtensions)
		{
			if (metadata == null)
				throw new ArgumentNullException ("metadata");
			
			if (wsdlImportExtensions == null) {
				wsdl_extensions = new KeyedByTypeCollection<IWsdlImportExtension> ();

				wsdl_extensions.Add (new DataContractSerializerMessageContractImporter ());
				wsdl_extensions.Add (new XmlSerializerMessageContractImporter ());
				wsdl_extensions.Add (new MessageEncodingBindingElementImporter ());
				wsdl_extensions.Add (new TransportBindingElementImporter ());
				wsdl_extensions.Add (new StandardBindingImporter ());
			} else {
				wsdl_extensions = new KeyedByTypeCollection<IWsdlImportExtension> (wsdlImportExtensions);
			}

			// It is okay to fill these members immediately when WsdlImporter.ctor() is invoked
			// i.e. after this .ctor(), those metadata docs are not considered anymore.
			this.metadata = metadata;
			this.wsdl_documents = new ServiceDescriptionCollection ();
			this.xmlschemas = new XmlSchemaSet ();
			this.policies = new List<XmlElement> ();
			this.contractHash = new Dictionary<PortType, ContractDescription> ();
			this.bindingHash = new Dictionary<WSBinding, ServiceEndpoint> ();
			this.endpointHash = new Dictionary<Port, ServiceEndpoint> ();

			foreach (MetadataSection ms in metadata.MetadataSections) {
				if (ms.Dialect == MetadataSection.ServiceDescriptionDialect &&
					ms.Metadata.GetType () == typeof (WSServiceDescription))
					wsdl_documents.Add ((WSServiceDescription) ms.Metadata);
				else
				if (ms.Dialect == MetadataSection.XmlSchemaDialect &&
					ms.Metadata.GetType () == typeof (XmlSchema))
					xmlschemas.Add ((XmlSchema) ms.Metadata);
			}
		}
コード例 #23
0
ファイル: ProtocolReflector.cs プロジェクト: Profit0004/mono
		void ImportBinding (ServiceDescription desc, Service service, TypeStubInfo typeInfo, string url, BindingInfo binfo)
		{
			port = new Port ();
			port.Name = portNames.AddUnique (binfo.Name, port);
			bool bindingFull = true;

			if (binfo.Namespace != desc.TargetNamespace)
			{
				if (binfo.Location == null || binfo.Location == string.Empty)
				{
					ServiceDescription newDesc = new ServiceDescription();
					newDesc.TargetNamespace = binfo.Namespace;
					newDesc.Name = binfo.Name;
					bindingFull = ImportBindingContent (newDesc, typeInfo, url, binfo);
					if (bindingFull) {
						int id = ServiceDescriptions.Add (newDesc);
						AddImport (desc, binfo.Namespace, GetWsdlUrl (url,id));
					}
				}
				else {
					AddImport (desc, binfo.Namespace, binfo.Location);
					bindingFull = true;
				}
			}
			else
				bindingFull = ImportBindingContent (desc, typeInfo, url, binfo);
				
			if (bindingFull)
			{
				port.Binding = new XmlQualifiedName (binding.Name, binfo.Namespace);
				
				int n = 0;
				string name = binfo.Name; 
				bool found;
				do {

					found = false;
					foreach (Port p in service.Ports)
						if (p.Name == name) { found = true; n++; name = binfo.Name + n; break; }
				}
				while (found);
				port.Name = name;
				service.Ports.Add (port);
			}

			if (binfo.WebServiceBindingAttribute != null && binfo.WebServiceBindingAttribute.ConformsTo != WsiProfiles.None && String.IsNullOrEmpty (binfo.WebServiceBindingAttribute.Name)) {
				BasicProfileViolationCollection violations = new BasicProfileViolationCollection ();
				desc.Types.Schemas.Add (Schemas);
				ServiceDescriptionCollection col = new ServiceDescriptionCollection ();
				col.Add (desc);
				ConformanceCheckContext ctx = new ConformanceCheckContext (col, violations);
				ctx.ServiceDescription = desc;
				ConformanceChecker[] checkers = WebServicesInteroperability.GetCheckers (binfo.WebServiceBindingAttribute.ConformsTo);
				foreach (ConformanceChecker checker in checkers) {
					ctx.Checker = checker;
					WebServicesInteroperability.Check (ctx, checker, binding);
					if (violations.Count > 0)
						throw new InvalidOperationException (violations [0].ToString ());
				}
			}
		}
コード例 #24
0
 private void AddDocument(
     string path, 
     object document, 
     XmlSchemas schemas,
     ServiceDescriptionCollection descriptions)
 {
     var serviceDescription = document as ServiceDescription;
     if (serviceDescription != null)
     {
         if (descriptions[serviceDescription.TargetNamespace] == null)
         {
             descriptions.Add(serviceDescription);
             var stringWriter = new StringWriter();
             var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};
             serviceDescription.Write(xmlWriter);
             Wsdls.Add(stringWriter.ToString());
         }
         else
         {
             // warn of duplicate service
         }
     }
     else
     {
         var schema = document as XmlSchema;
         if (schema != null)
         {
             if (schemas[schema.TargetNamespace] == null)
             {
                 schemas.Add(schema);
                 var stringWriter = new StringWriter();
                 var xmlWriter = new XmlTextWriter(stringWriter) {Formatting = Formatting.Indented};
                 schema.Write(xmlWriter);
                 Xsds.Add(stringWriter.ToString());
             }
             else
             {
                 // warn of duplicate schema
             }
         }
     }
 }