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
|
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.ComIntegration
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.ServiceModel.Configuration;
using System.ServiceModel.Diagnostics;
class WebHostedComPlusServiceHost : ComPlusServiceHost
{
public WebHostedComPlusServiceHost(string webhostParams, Uri[] baseAddresses)
{
foreach (Uri address in baseAddresses)
this.InternalBaseAddresses.Add(address);
// Split up the parameter string into "clsid,appid".
//
string[] parameters = webhostParams.Split(',');
if (parameters.Length != 2)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ServiceStringFormatError,
webhostParams)));
}
Guid clsid;
Guid appId;
if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[0], out clsid))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ServiceStringFormatError,
webhostParams)));
}
if (!DiagnosticUtility.Utility.TryCreateGuid(parameters[1], out appId))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ServiceStringFormatError,
webhostParams)));
}
// "B" == "With dashes and curly braces"
// (The catalog gives us GUIDs in this format)
//
string clsidString = clsid.ToString("B").ToUpperInvariant();
// Look up the COM+ AdminSDK information for this
// AppID/CLSID pair.
//
ComCatalogObject application;
application = CatalogUtil.FindApplication(appId);
if (application == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ApplicationNotFound,
appId.ToString("B").ToUpperInvariant())));
}
ComCatalogCollection classes;
classes = application.GetCollection("Components");
ComCatalogObject classObject = null;
foreach (ComCatalogObject tempClassObject in classes)
{
string otherClsid = (string)tempClassObject.GetValue("CLSID");
if (clsidString.Equals(
otherClsid,
StringComparison.OrdinalIgnoreCase))
{
classObject = tempClassObject;
break;
}
}
if (classObject == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ClsidNotInApplication,
clsidString,
appId.ToString("B").ToUpperInvariant())));
}
// Load up Indigo configuration, get the configuration for
// this service.
//
ServicesSection services = ServicesSection.GetSection();
ServiceElement service = null;
foreach (ServiceElement serviceInConfig in services.Services)
{
Guid clsidFromConfig = Guid.Empty;
Guid appidFromConfig = Guid.Empty;
string[] serviceParams = serviceInConfig.Name.Split(',');
if (serviceParams.Length != 2)
{
continue;
}
if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[0], out appidFromConfig))
{
// We are tolerant of having non COM+ based services
// for webhost.
continue;
}
if (!DiagnosticUtility.Utility.TryCreateGuid(serviceParams[1], out clsidFromConfig))
{
// We are tolerant of having non COM+ based services
// for webhost.
continue;
}
if (clsidFromConfig == clsid && appidFromConfig == appId)
{
service = serviceInConfig;
break;
}
}
if (service == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(System.ServiceModel.ComIntegration.Error.ListenerInitFailed(
SR.GetString(SR.ClsidNotInConfiguration,
clsidString)));
}
// Hosting mode evaluation
//
HostingMode hostingMode;
int activation = (int)application.GetValue("Activation");
if (activation == 0)
{
hostingMode = HostingMode.WebHostInProcess;
}
else
{
hostingMode = HostingMode.WebHostOutOfProcess;
}
// Now we have everything we need, do common
// initialization.
//
Initialize(clsid,
service,
application,
classObject,
hostingMode);
}
}
}
|