I have a WCF service which I am hosting as a Windows Service. I normally go to VS command prompt and install the service using installutil.exe, then modify the base address of the service in app.config according to the machine name that I am installing it on and run the service.
base address goes like this:
<endpoint address="http://MACHINE_NAME/NFCReader/" binding="webHttpBinding"/>
I modify the MACHINE_NAME in the app.config file.
I want to use inno setup to do the same for me.
What I want is when the user run the setup.exe file to install the service, I want to prompt the user for base address of the service and use that address to host it. I am not able to figure out if it is possible at all OR how to do it.
Any help please? Thanks in advance. :)
Just an example I use to replace string in my app config.
I'm sure it can be done better :-)
What I replace is:
add key="AppVersion" value="YYMMDD.HH.MM"
[Code]
procedure Update;
var
C: AnsiString;
CU: String;
begin
LoadStringFromFile(ExpandConstant('{src}\CdpDownloader.exe_base.config'), C);
CU := C;
StringChange(CU, 'YYMMDD.HH.MM', GetDateTimeString('yymmdd/hh:nn', '.', '.'));
C := CU;
SaveStringToFile(ExpandConstant('{src}\Config\CdpDownloader.exe.config'), C, False);
end;
function InitializeSetup: Boolean;
begin
Update;
result := True;
end;
I would recommend you to use XML parser for updating your configuration files. The following function can help you with it. It uses MSXML as a file parser:
[Code]
const
ConfigEndpointPath = '//configuration/system.serviceModel/client/endpoint';
function ChangeEndpointAddress(const FileName, Address: string): Boolean;
var
XMLNode: Variant;
XMLDocument: Variant;
begin
Result := False;
XMLDocument := CreateOleObject('Msxml2.DOMDocument.6.0');
try
XMLDocument.async := False;
XMLDocument.preserveWhiteSpace := True;
XMLDocument.load(FileName);
if (XMLDocument.parseError.errorCode <> 0) then
RaiseException(XMLDocument.parseError.reason)
else
begin
XMLDocument.setProperty('SelectionLanguage', 'XPath');
XMLNode := XMLDocument.selectSingleNode(ConfigEndpointPath);
XMLNode.setAttribute('address', Address);
XMLDocument.save(FileName);
Result := True;
end;
except
MsgBox('An error occured during processing application ' +
'config file!' + #13#10 + GetExceptionMessage, mbError, MB_OK);
end;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With