1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.Administration
{
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Runtime;
using System.ServiceModel;
using System.ServiceModel.Description;
sealed class ServiceInfo
{
KeyedByTypeCollection<IServiceBehavior> behaviors;
EndpointInfoCollection endpoints;
ServiceHostBase service;
string serviceName;
internal ServiceInfo(ServiceHostBase service)
{
this.service = service;
this.behaviors = service.Description.Behaviors;
this.serviceName = service.Description.Name;
this.endpoints = new EndpointInfoCollection(service.Description.Endpoints, this.ServiceName);
}
public string ConfigurationName
{
get { return this.service.Description.ConfigurationName; }
}
public string DistinguishedName
{
get { return this.serviceName + "@" + this.FirstAddress; }
}
public string FirstAddress
{
get
{
Fx.Assert(null != this.Service.BaseAddresses, "");
string address = "";
if (this.Service.BaseAddresses.Count > 0)
{
Fx.Assert(null != this.Service.BaseAddresses[0], "");
address = this.Service.BaseAddresses[0].ToString();
}
else if (this.Endpoints.Count > 0)
{
Uri addressUri = this.Endpoints[0].Address;
if (null != addressUri)
{
address = addressUri.ToString();
}
}
return address;
}
}
public string Name
{
get { return this.serviceName; }
}
public string Namespace
{
get { return this.service.Description.Namespace; }
}
public string ServiceName
{
get { return this.serviceName; }
}
public ServiceHostBase Service
{
get
{
return this.service;
}
}
public KeyedByTypeCollection<IServiceBehavior> Behaviors
{
get
{
return this.behaviors;
}
}
public CommunicationState State
{
get
{
return this.Service.State;
}
}
public EndpointInfoCollection Endpoints
{
get
{
return this.endpoints;
}
}
public string[] Metadata
{
get
{
string[] result = null;
ServiceMetadataExtension metadataExtension = service.Extensions.Find<ServiceMetadataExtension>();
if (null != metadataExtension)
{
Collection<string> metadataStrings = new Collection<string>();
try
{
foreach (MetadataSection section in metadataExtension.Metadata.MetadataSections)
{
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
{
if (section.Metadata is System.Web.Services.Description.ServiceDescription)
{
System.Web.Services.Description.ServiceDescription metadata = (System.Web.Services.Description.ServiceDescription)section.Metadata;
metadata.Write(sw);
metadataStrings.Add(sw.ToString());
}
else if (section.Metadata is System.Xml.XmlElement)
{
System.Xml.XmlElement metadata = (System.Xml.XmlElement)section.Metadata;
using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create(sw))
{
metadata.WriteTo(xmlWriter);
metadataStrings.Add(sw.ToString());
}
}
else if (section.Metadata is System.Xml.Schema.XmlSchema)
{
System.Xml.Schema.XmlSchema metadata = (System.Xml.Schema.XmlSchema)section.Metadata;
metadata.Write(sw);
metadataStrings.Add(sw.ToString());
}
else
{
metadataStrings.Add(section.Metadata.ToString());
}
}
}
}
catch (InvalidOperationException e)
{
metadataStrings.Add(e.ToString());
}
result = new string[metadataStrings.Count];
metadataStrings.CopyTo(result, 0);
}
return result;
}
}
}
}
|