gpt4 book ai didi

wcf - 如何检查 WCF 是否已在 IIS 中注册

转载 作者:行者123 更新时间:2023-12-04 14:26:49 24 4
gpt4 key购买 nike

我正在制作安装程序并想检查 WCF 是否已在 IIS 中注册

最佳答案

检查 IIS ScriptMap 中的 .svc 扩展名。为此,您可以从以 Javascript、VBScript 或 C/C++ 实现的 WIX 自定义操作中使用 WMI。这是 Javascript 中的一个示例:

// IsWcf.js
// ------------------------------------------------------------------
//
// detect if WCF is installed; suitable for use within a WIX Custom Action.
//
// Copyright 2010, Cheeso.
//
// Licensed under the MS Public License
// http://opensource.org/licenses/ms-pl.html
//
// To use this as a Custom Action in a WIX project, register it this way:
//
// <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
// <Fragment>
// <Binary Id="B.JavaScript" SourceFile="CustomActions.js" />
// <CustomAction Id="CA.DetectWcf"
// BinaryKey="B.JavaScript"
// JScriptCall="DetectWcf_CA"
// Execute="immediate"
// Return="check" />
// </Fragment>
// </Wix>
//
// And invoke it this way:
//
// <InstallUISequence>
// <Custom Action="CA.DetectWcf" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
// </InstallUISequence>
//
//
// =======================================================


// http://msdn.microsoft.com/en-us/library/aa371254(VS.85).aspx
var MsiActionStatus = {
None : 0,
Ok : 1, // success
Cancel : 2,
Abort : 3,
Retry : 4, // aka suspend?
Ignore : 5 // skip remaining actions; this is not an error.
};

var MsgKind = {
Error : 0x01000000,
Warning : 0x02000000,
User : 0x03000000,
Log : 0x04000000
};


// Format a number as hex. Quantities over 7ffffff will be displayed properly.
function decimalToHexString(number) {
if (number < 0)
number = 0xFFFFFFFF + number + 1;
return number.toString(16).toUpperCase();
}

function LogMessage(s) {
LogMessage2(s,MsgKind.Log);
}

function LogMessage2(s,kind){
if (typeof Session !== "undefined") {
var record = Session.Installer.CreateRecord(0);
record.StringData(0) = "CustomActions: " + msg;
Session.Message(kind, record);
}
else {
WScript.echo(s);
}
}

function LogException(loc, exc) {
var s = "Exception {" + loc + "}: 0x" + decimalToHexString(exc.number) + " : " + exc.message;
if (typeof Session !== "undefined") {
var record = Session.Installer.CreateRecord(0);
record.StringData(0) = s;
Session.Message(MsgKind.Error + Icons.Critical + Buttons.btnOkOnly, record);
}
else {
LogMessage(s);
}
}

function stringEndsWith(subject, end) {
return (subject.match(end+"$") == end);
}

function DetectWcf_CA(website) {
try {
LogMessage("DetectWcf_CA() ENTER");

if (website == null) {
website = "W3SVC"; // default value
}

LogMessage("website name(" + website + ")");

var query = ( website == "W3SVC" )
? "SELECT * FROM IIsWebServiceSetting"
: "SELECT * FROM IIsWebServerSetting WHERE Name = '" + website + "'";

var iis = GetObject("winmgmts://localhost/root/MicrosoftIISv2");

var settings = iis.ExecQuery(query);
LogMessage("WMI Query results : " + typeof settings);

if ( settings == null ) {
LogMessage("Cannot query IIS.");
return MsiActionStatus.Abort;
}

var item;
if ( settings.Count != 0 ) {
for(var e = new Enumerator(settings); !e.atEnd(); e.moveNext()) {
item = e.item();
}
}

var scriptMaps = item.ScriptMaps.toArray();
var isSvcMapPresent = false;
var svcMapIndex = -1;
for (var i=0; i<scriptMaps.length; i++) {
var map = scriptMaps[i];
for(var e = new Enumerator(map.Properties_); !e.atEnd(); e.moveNext()) {
item = e.item();
if (item.Name == "Extensions" && item.Value == ".svc" && svcMapIndex == -1 ) {
svcMapIndex = i;
}
else if (i == svcMapIndex && item.Name == "ScriptProcessor" && stringEndsWith(item.Value,"aspnet_isapi.dll")) {
isSvcMapPresent = true;
}
}
}

LogMessage("DetectWcf_CA(): Is WCF Present?: " + isSvcMapPresent);

// works in WIX Custom Action only:
if (typeof Session !== "undefined") {
Session.Property("ISWCF") = (isSvcMapPresent) ? "1" : "0";
}

LogMessage("DetectWcf_CA() EXIT (Ok)");
}
catch (exc1) {
LogException("DetectWcf_CA", exc1);
return MsiActionStatus.Abort;
}
return MsiActionStatus.Ok;
}


// actually run it, only if being invoked outside of WIX
if (typeof Session == "undefined") {
DetectWcf_CA("W3SVC") ;
}

关于wcf - 如何检查 WCF 是否已在 IIS 中注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2417143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com