Beispiel #1
0
        void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription serviceDescription,
            ServiceHostBase serviceHostBase)
        {
            WsdlExporter wsdlExporter = new WsdlExporter();
            wsdlExporter.ExportEndpoints(serviceDescription.Endpoints,
                new XmlQualifiedName(serviceDescription.Name, serviceDescription.Namespace));

            foreach (ChannelDispatcher cDispatcher in serviceHostBase.ChannelDispatchers)
                foreach (EndpointDispatcher endpointDispatcher in cDispatcher.Endpoints)
                    endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
                        new XsdValidationInspector(wsdlExporter.GeneratedXmlSchemas));
        }
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, System.ServiceModel.Description.ServiceDescription service)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         WsdlExporter exporter = new WsdlExporter();
         string ns = "http://tempuri.org/";
         XmlQualifiedName wsdlServiceQName = new XmlQualifiedName("comPlusService", ns);
         exporter.ExportEndpoints(service.Endpoints, wsdlServiceQName);
         System.Web.Services.Description.ServiceDescription wsdl = exporter.GeneratedWsdlDocuments[ns];
         ComPlusServiceHostStartedServiceDetailsSchema schema = new ComPlusServiceHostStartedServiceDetailsSchema(info.AppID, info.Clsid, wsdl);
         TraceUtility.TraceEvent(type, traceCode, System.ServiceModel.SR.GetString(description), (TraceRecord) schema);
     }
 }
 public static void Trace(TraceEventType type, int traceCode, string description, ServiceInfo info, ServiceDescription service)
 {
     if (DiagnosticUtility.ShouldTrace(type))
     {
         WsdlExporter exporter = new WsdlExporter();
         string serviceNs = NamingHelper.DefaultNamespace;
         XmlQualifiedName serviceQName = new XmlQualifiedName("comPlusService", serviceNs);
         exporter.ExportEndpoints(service.Endpoints, serviceQName);
         WsdlNS.ServiceDescription wsdl = exporter.GeneratedWsdlDocuments[serviceNs];
         ComPlusServiceHostStartedServiceDetailsSchema record =
             new ComPlusServiceHostStartedServiceDetailsSchema(info.AppID, info.Clsid, wsdl);
         TraceUtility.TraceEvent(type, traceCode, ServiceModelSR.GetString(description), record);
     }
 }
Beispiel #4
0
 static void Main(string[] args)
 {
     ContractDescription contract = ContractDescription.GetContract(typeof(IOrderService));
     EndpointAddress address1 = new EndpointAddress("http://127.0.0.1/orderservice");
     EndpointAddress address2 = new EndpointAddress("net.tcp://127.0.0.1/orderservice");
     ServiceEndpoint endpoint1 = new ServiceEndpoint(contract, new WS2007HttpBinding(), address1);
     ServiceEndpoint endpoint2 = new ServiceEndpoint(contract, new NetTcpBinding(), address2);
     XmlQualifiedName serviceName = new XmlQualifiedName("OrderService", "http://www.artech.com/services/");
     WsdlExporter exporter = new WsdlExporter();
     exporter.ExportEndpoints(new ServiceEndpoint[] { endpoint1, endpoint2 }, serviceName);
     MetadataSet metadata = exporter.GetGeneratedMetadata();
     using (XmlWriter writer = new XmlTextWriter("metadata.xml", Encoding.UTF8))
     {
         metadata.WriteTo(writer);
     }
     Process.Start("metadata.xml");
 }
 private static MetadataSet GetExportedMetadata(ServiceDescription serviceDescription)
 {
     Collection<ServiceEndpoint> endpoints = new Collection<ServiceEndpoint>();
     foreach (var endpoint in serviceDescription.Endpoints)
     {
         if (endpoint.Contract.ContractType == typeof(IMetadataProvisionService))
         {
             continue;
         }
         ServiceEndpoint newEndpoint = new ServiceEndpoint(endpoint.Contract, endpoint.Binding, endpoint.Address);
         newEndpoint.Name = endpoint.Name;
         foreach (var behavior in endpoint.Behaviors)
         {
             newEndpoint.Behaviors.Add(behavior);
         }
         endpoints.Add(newEndpoint);
     }
     WsdlExporter exporter = new WsdlExporter();
     XmlQualifiedName wsdlServiceQName = new XmlQualifiedName(serviceDescription.Name, serviceDescription.Namespace);
     exporter.ExportEndpoints(endpoints, wsdlServiceQName);
     MetadataSet metadata = exporter.GetGeneratedMetadata();
     return metadata;
 }
            internal MetadataSet GenerateMetadata()
            {
                if (this.behavior.ExternalMetadataLocation == null || this.behavior.ExternalMetadataLocation.ToString() == string.Empty)
                {
                    if (this.metadataGenerationException != null)
                    {
                        throw this.metadataGenerationException;
                    }

                    try
                    {
                        MetadataExporter             exporter          = this.behavior.MetadataExporter;
                        XmlQualifiedName             serviceName       = new XmlQualifiedName(this.description.Name, this.description.Namespace);
                        Collection <ServiceEndpoint> exportedEndpoints = new Collection <ServiceEndpoint>();
                        foreach (ServiceEndpoint endpoint in this.description.Endpoints)
                        {
                            ServiceMetadataContractBehavior contractBehavior = endpoint.Contract.Behaviors.Find <ServiceMetadataContractBehavior>();

                            // if contract behavior exists, generate metadata when the behavior allows metadata generation
                            // if contract behavior doesn't exist, generate metadata only for non system endpoints
                            if ((contractBehavior != null && !contractBehavior.MetadataGenerationDisabled) ||
                                (contractBehavior == null && !endpoint.IsSystemEndpoint))
                            {
                                EndpointAddress    address            = null;
                                EndpointDispatcher endpointDispatcher = GetListenerByID(this.host.ChannelDispatchers, endpoint.Id);
                                if (endpointDispatcher != null)
                                {
                                    address = endpointDispatcher.EndpointAddress;
                                }
                                ServiceEndpoint exportedEndpoint = new ServiceEndpoint(endpoint.Contract);
                                exportedEndpoint.Binding = endpoint.Binding;
                                exportedEndpoint.Name    = endpoint.Name;
                                exportedEndpoint.Address = address;
                                foreach (IEndpointBehavior behavior in endpoint.Behaviors)
                                {
                                    exportedEndpoint.Behaviors.Add(behavior);
                                }
                                exportedEndpoints.Add(exportedEndpoint);
                            }
                        }
                        WsdlExporter wsdlExporter = exporter as WsdlExporter;
                        if (wsdlExporter != null)
                        {
                            // Pass the BindingParameterCollection into the ExportEndpoints method so that the binding parameters can be using to export WSDL correctly.
                            // The binding parameters are used in BuildChannelListener, during which they can modify the configuration of the channel in ways that might have to
                            // be communicated in the WSDL. For example, in the case of Multi-Auth, the AuthenticationSchemesBindingParameter is used during BuildChannelListener
                            // to set the AuthenticationSchemes supported by the virtual directory on the HttpTransportBindingElement.  These authentication schemes also need
                            // to be in the WSDL, so that clients know what authentication schemes are supported by the service.  (see CSDMain #180381)
                            Fx.Assert(this.host != null, "ServiceHostBase field on MetadataExtensionInitializer should never be null.");
                            wsdlExporter.ExportEndpoints(exportedEndpoints, serviceName, this.host.GetBindingParameters(exportedEndpoints));
                        }
                        else
                        {
                            foreach (ServiceEndpoint endpoint in exportedEndpoints)
                            {
                                exporter.ExportEndpoint(endpoint);
                            }
                        }

                        if (exporter.Errors.Count > 0 && DiagnosticUtility.ShouldTraceWarning)
                        {
                            TraceWsdlExportErrors(exporter);
                        }

                        return(exporter.GetGeneratedMetadata());
                    }
                    catch (Exception e)
                    {
                        this.metadataGenerationException = e;
                        throw;
                    }
                }
                return(null);
            }
 internal MetadataSet GenerateMetadata()
 {
     if ((this.behavior.ExternalMetadataLocation == null) || (this.behavior.ExternalMetadataLocation.ToString() == string.Empty))
     {
         if (this.metadataGenerationException != null)
         {
             throw this.metadataGenerationException;
         }
         try
         {
             MetadataExporter             metadataExporter = this.behavior.MetadataExporter;
             XmlQualifiedName             wsdlServiceQName = new XmlQualifiedName(this.description.Name, this.description.Namespace);
             Collection <ServiceEndpoint> endpoints        = new Collection <ServiceEndpoint>();
             foreach (ServiceEndpoint endpoint in this.description.Endpoints)
             {
                 ServiceMetadataContractBehavior behavior = endpoint.Contract.Behaviors.Find <ServiceMetadataContractBehavior>();
                 if (((behavior != null) && !behavior.MetadataGenerationDisabled) || ((behavior == null) && !endpoint.IsSystemEndpoint))
                 {
                     EndpointAddress    endpointAddress = null;
                     EndpointDispatcher listenerByID    = ServiceMetadataBehavior.GetListenerByID(this.host.ChannelDispatchers, endpoint.Id);
                     if (listenerByID != null)
                     {
                         endpointAddress = listenerByID.EndpointAddress;
                     }
                     ServiceEndpoint item = new ServiceEndpoint(endpoint.Contract)
                     {
                         Binding = endpoint.Binding,
                         Name    = endpoint.Name,
                         Address = endpointAddress
                     };
                     foreach (IEndpointBehavior behavior2 in endpoint.Behaviors)
                     {
                         item.Behaviors.Add(behavior2);
                     }
                     endpoints.Add(item);
                 }
             }
             WsdlExporter exporter2 = metadataExporter as WsdlExporter;
             if (exporter2 != null)
             {
                 exporter2.ExportEndpoints(endpoints, wsdlServiceQName);
             }
             else
             {
                 foreach (ServiceEndpoint endpoint3 in endpoints)
                 {
                     metadataExporter.ExportEndpoint(endpoint3);
                 }
             }
             if ((metadataExporter.Errors.Count > 0) && DiagnosticUtility.ShouldTraceWarning)
             {
                 TraceWsdlExportErrors(metadataExporter);
             }
             return(metadataExporter.GetGeneratedMetadata());
         }
         catch (Exception exception)
         {
             this.metadataGenerationException = exception;
             throw;
         }
     }
     return(null);
 }