tags:

views:

115

answers:

2

i am making a installer and want to check whether the WCF is already registered with IIS

A: 

servicemodelreg.exe -lv

http://msdn.microsoft.com/en-us/library/ms732012.aspx

Joshua
how do i check it programatically
taher chhabrawala
A: 

Check for the .svc extension in the IIS ScriptMaps. To do that, you can use WMI from a WIX Custom Action implemented in Javascript, VBScript, or C/C++. Here's an example in 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"&gt;
//     <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 bbeing invoked outside of WIX
if (typeof Session == "undefined") {
    DetectWcf_CA("W3SVC") ;
}
Cheeso