7

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. :)

Newbee
  • 1,379
  • 2
  • 16
  • 36

2 Answers2

5

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;
codeConcussion
  • 12,739
  • 8
  • 49
  • 62
RobeN
  • 5,346
  • 1
  • 33
  • 50
  • 1
    Yes, for instance by using an XML parser. If you're familiar with MSXML, you might follow [`this post`](http://stackoverflow.com/a/11254218/960757). It's quite simple to extend it to your needs. A fast XML parser for InnoSetup is on my task list (but will take some time). – TLama Mar 25 '13 at 15:07
  • 1
    An XML parser/writer is an unnecessary complication if you have a known-unique marker string in a template file that you can replace (similar to the code above). It is, however, a good idea if you need to be able to modify files that you can't inject such markers into (eg. if you need to update a file already installed on the user's system). Note however that the code above has a bug: `DateTime` is being treated as an ISPP value instead of a code function. It should be called directly, not via `ExpandConstant`. – Miral Mar 26 '13 at 20:05
  • Corrected. Thanks for the tip. – RobeN Mar 27 '13 at 09:00
  • @RobeN Thanks for the answer. It worked for me. But I need little change in my script i.e I have to change the value by using the key(here you used the key itself). is there anything to do so? if not then i'm happy with this answer. – Myanju Feb 20 '15 at 10:31
3

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;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • 2
    I can help you with the rest of your requirement (create an input page before the installation starts to let the user enter the endpoint address and call the above function after the installation succeed), if you need to. Just let me know... – TLama Mar 25 '13 at 18:18
  • How is it going ? Any feedback will be appreciated ;-) – TLama May 10 '13 at 08:56