本文整理汇总了C#中System.ServiceModel.ServiceHost.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceHost.GetType方法的具体用法?C# ServiceHost.GetType怎么用?C# ServiceHost.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.ServiceHost
的用法示例。
在下文中一共展示了ServiceHost.GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
public void Start()
{
this._UniqueId = _serviceConfig.UniqueId;
string httpEndPstr = @"http://{0}:{1}/WcfPortal".FormatWith(_serviceConfig.HostAddress, _serviceConfig.HostPort);
Uri httpUri = new Uri(httpEndPstr);
_serviceHost = new ServiceHost(typeof(SAF.EntityFramework.Server.Hosts.WcfPortal), httpUri);
Type t = _serviceHost.GetType();
object obj = t.Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", true,
BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null,
new object[] { false, Int32.MaxValue }, null, null);
IServiceBehavior myServiceBehavior = obj as IServiceBehavior;
if (myServiceBehavior != null)
{
_serviceHost.Description.Behaviors.Add(myServiceBehavior);
}
if (_serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>() == null)
{
var behavior = new ServiceMetadataBehavior();
//交换方式
behavior.HttpGetEnabled = true;
//元数据交换地址
behavior.HttpGetUrl = httpUri;
//将行为添加到宿主上
_serviceHost.Description.Behaviors.Add(behavior);
}
if (_serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>() == null)
{
var behavior = new ServiceDebugBehavior();
//交换方式
behavior.IncludeExceptionDetailInFaults = true;
//将行为添加到宿主上
_serviceHost.Description.Behaviors.Add(behavior);
}
_serviceHost.AddServiceEndpoint(typeof(SAF.EntityFramework.Server.Hosts.IWcfPortal), new WSHttpBinding(SecurityMode.None), "");
_serviceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
_thread = new Thread(RunService);
_thread.IsBackground = true;
_thread.Start();
}
示例2: ApplyServiceHostSettings
/// <summary>
/// Applies the service host settings.
/// </summary>
/// <param name="host">Host.</param>
/// <param name="useCustomBehaviours">If set to <c>true</c> use custom behaviours.</param>
private static void ApplyServiceHostSettings(ServiceHost host, bool useCustomBehaviours = false)
{
host.OpenTimeout = host.CloseTimeout = _timeout;
ServiceDebugBehavior sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null)
host.Description.Behaviors.Add(sdb = new ServiceDebugBehavior());
sdb.IncludeExceptionDetailInFaults = true;
host.AddServiceEndpoint(typeof(IRepository),
new NetTcpBinding(SecurityMode.None)
{
MaxBufferSize = 4096,
ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas()
{
MaxStringContentLength = 32768
}
},
new Uri("net.tcp://localhost:3334/ArtefactRepository"));
if (useCustomBehaviours)
ApplyServiceHostBehaviours(host);
host.Opened += (sender, e) => _output.WriteLine("{0}: Opened", host.GetType().Name);
host.Opening += (sender, e) => _output.WriteLine("{0}: Opening", host.GetType().Name);
host.Closed += (sender, e) => _output.WriteLine("{0}: Closed", host.GetType().Name);
host.Closing += (sender, e) => _output.WriteLine("{0}: Closing", host.GetType().Name);
host.Faulted += (sender, e) => _error.WriteLine("{0}: Faulted", host.GetType().Name);
host.UnknownMessageReceived += (sender, e) => _error.WriteLine("{0}: UnknownMessageReceived", host.GetType().Name);
}
示例3: CreateServiceHost
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(serviceType, baseAddresses); //base.CreateServiceHost(serviceType, baseAddresses);
Type contractType = FindServiceContractInterface(serviceType);
host.AddServiceEndpoint(contractType, FindBinding(m_BindingType), "");
ServiceMetadataBehavior b1 = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (b1 == null)
{
b1 = new ServiceMetadataBehavior() { HttpGetEnabled = true };
host.Description.Behaviors.Add(b1);
}
else
{
b1.HttpGetEnabled = true;
}
StandardExceptionBehavior b = host.Description.Behaviors.Find<StandardExceptionBehavior>();
if (b == null)
{
host.Description.Behaviors.Add(new StandardExceptionBehavior(m_BizExceptionTypeName, m_ExceptionHandlerTypeName));
}
//if (url.IndexOf("http://") < 0)
//{
// b1.HttpGetUrl = new Uri(string.Format("http://{0}{1}{2}", hostIP, (service.Port > 0 ? (":" + service.Port) : string.Empty), url));
//}
ServiceDebugBehavior b2 = host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (b2 == null)
{
host.Description.Behaviors.Add(new ServiceDebugBehavior() { IncludeExceptionDetailInFaults = true });
}
else
{
b2.IncludeExceptionDetailInFaults = true;
}
ServiceBehaviorAttribute bb = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
if (bb == null)
{
bb = new ServiceBehaviorAttribute();
host.Description.Behaviors.Add(bb);
}
bb.ConcurrencyMode = ConcurrencyMode.Multiple;
bb.AddressFilterMode = AddressFilterMode.Any;
bb.InstanceContextMode = InstanceContextMode.Single;
bb.MaxItemsInObjectGraph = Int32.MaxValue;
if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
{
AspNetCompatibilityRequirementsAttribute a = host.Description.Behaviors.Find<AspNetCompatibilityRequirementsAttribute>();
if (a == null)
{
host.Description.Behaviors.Add(new AspNetCompatibilityRequirementsAttribute() { RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed });
}
else
{
a.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
}
}
//------- 设置 dataContractSerializer的 maxItemsInObjectGraph属性为int.MaxValue
Type t = host.GetType();
object obj = t.Assembly.CreateInstance("System.ServiceModel.Dispatcher.DataContractSerializerServiceBehavior", true, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic, null, new object[] { false, int.MaxValue }, null, null);
IServiceBehavior myServiceBehavior = obj as IServiceBehavior;
if (myServiceBehavior != null)
{
host.Description.Behaviors.Add(myServiceBehavior);
}
//-------
return host;
}