Programmatically change web service information in app.config

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Jocelyn

    Programmatically change web service information in app.config

    Hi

    How do I programmaticall y change (read/write) the values in this app.config
    file at runtime? Specifically I want to change the client endpoint address
    but it would be nice to change other values too. I thought this is what
    ServiceHost is for but is seems way more complicated to use for what I'm
    trying to do.

    <system.service Model>
    <bindings>
    <basicHttpBindi ng>
    <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
    openTimeout="00 :01:00"
    receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
    allowCookies="f alse"
    bypassProxyOnLo cal="false"
    hostNameCompari sonMode="Strong Wildcard"
    maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
    maxReceivedMess ageSize="671088 64"
    messageEncoding ="Text" textEncoding="u tf-8"
    transferMode="B uffered"
    useDefaultWebPr oxy="true">
    <readerQuotas maxDepth="32" maxStringConten tLength="8192"
    maxArrayLength= "16384"
    maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
    <security mode="None">
    <transport clientCredentia lType="None"
    proxyCredential Type="None"
    realm="" />
    <message clientCredentia lType="UserName "
    algorithmSuite= "Default" />
    </security>
    </binding>
    </basicHttpBindin g>
    </bindings>
    <client>
    <endpoint address="http://webservice.com/Service.asmx"
    binding="basicH ttpBinding" bindingConfigur ation="DataServ iceSoap"
    contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
    </client>
    </system.serviceM odel>

    Many thanks
    Andrew


  • Alvin Bruney [ASP.NET MVP]

    #2
    Re: Programmaticall y change web service information in app.config

    It's a file, you can read and write it as normal. However, you will restart
    the application. Now, step back a bit. Endpoints are established ahead of
    time and configured accordingly. Your requirement is about the same as
    rewriting a browser url so that clients can hit this new url. Why not
    publish the url ahead of time? Why the strange requirement?

    --

    Regards,
    Alvin Bruney [MVP ASP.NET]

    [Shameless Author plug]
    Download OWC Black Book, 2nd Edition
    Exclusively on www.lulu.com/owc $15.00
    Need a free copy of VSTS 2008 w/ MSDN Premium?

    -------------------------------------------------------


    "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
    news:ODLig9W$IH A.4800@TK2MSFTN GP03.phx.gbl...
    Hi
    >
    How do I programmaticall y change (read/write) the values in this
    app.config file at runtime? Specifically I want to change the client
    endpoint address but it would be nice to change other values too. I
    thought this is what ServiceHost is for but is seems way more complicated
    to use for what I'm trying to do.
    >
    <system.service Model>
    <bindings>
    <basicHttpBindi ng>
    <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
    openTimeout="00 :01:00"
    receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
    allowCookies="f alse"
    bypassProxyOnLo cal="false"
    hostNameCompari sonMode="Strong Wildcard"
    maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
    maxReceivedMess ageSize="671088 64"
    messageEncoding ="Text" textEncoding="u tf-8"
    transferMode="B uffered"
    useDefaultWebPr oxy="true">
    <readerQuotas maxDepth="32" maxStringConten tLength="8192"
    maxArrayLength= "16384"
    maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
    <security mode="None">
    <transport clientCredentia lType="None"
    proxyCredential Type="None"
    realm="" />
    <message clientCredentia lType="UserName "
    algorithmSuite= "Default" />
    </security>
    </binding>
    </basicHttpBindin g>
    </bindings>
    <client>
    <endpoint address="http://webservice.com/Service.asmx"
    binding="basicH ttpBinding" bindingConfigur ation="DataServ iceSoap"
    contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
    </client>
    </system.serviceM odel>
    >
    Many thanks
    Andrew
    >

    Comment

    • Jeff Dillon

      #3
      Re: Programmaticall y change web service information in app.config

      "Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
      message news:FBE1F43F-6713-49EA-B21C-58FDD09148E2@mi crosoft.com...
      It's a file, you can read and write it as normal. However, you will
      restart the application. Now, step back a bit. Endpoints are established
      ahead of time and configured accordingly. Your requirement is about the
      same as rewriting a browser url so that clients can hit this new url. Why
      not publish the url ahead of time? Why the strange requirement?
      >
      --
      >
      Regards,
      Alvin Bruney [MVP ASP.NET]
      >
      [Shameless Author plug]
      Download OWC Black Book, 2nd Edition
      Exclusively on www.lulu.com/owc $15.00
      Need a free copy of VSTS 2008 w/ MSDN Premium?

      -------------------------------------------------------
      >
      >
      "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
      news:ODLig9W$IH A.4800@TK2MSFTN GP03.phx.gbl...
      >Hi
      >>
      >How do I programmaticall y change (read/write) the values in this
      >app.config file at runtime? Specifically I want to change the client
      >endpoint address but it would be nice to change other values too. I
      >thought this is what ServiceHost is for but is seems way more complicated
      >to use for what I'm trying to do.
      >>
      > <system.service Model>
      > <bindings>
      > <basicHttpBindi ng>
      > <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
      >openTimeout="0 0:01:00"
      > receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
      >allowCookies=" false"
      > bypassProxyOnLo cal="false"
      >hostNameCompar isonMode="Stron gWildcard"
      > maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
      >maxReceivedMes sageSize="67108 864"
      > messageEncoding ="Text" textEncoding="u tf-8"
      >transferMode=" Buffered"
      > useDefaultWebPr oxy="true">
      > <readerQuotas maxDepth="32" maxStringConten tLength="8192"
      >maxArrayLength ="16384"
      > maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
      > <security mode="None">
      > <transport clientCredentia lType="None"
      >proxyCredentia lType="None"
      > realm="" />
      > <message clientCredentia lType="UserName "
      >algorithmSuite ="Default" />
      > </security>
      > </binding>
      > </basicHttpBindin g>
      > </bindings>
      > <client>
      > <endpoint address="http://webservice.com/Service.asmx"
      > binding="basicH ttpBinding"
      >bindingConfigu ration="DataSer viceSoap"
      > contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
      > </client>
      > </system.serviceM odel>
      >>
      >Many thanks
      >Andrew
      >>
      No, that is not a good solution. How do you programmaticall y change the
      endpoints? We have the same requirement. I suspect we can just define two
      endpoints (binding names) in the config as you suggest however, then choose
      which one to use at runtime. We have an application that needs to easily
      switch between sandbox and production environment web services.

      Jeff


      Comment

      • Andrew Jocelyn

        #4
        Re: Programmaticall y change web service information in app.config

        OK, this is the situation.

        The windows form client is a ClickOnce app and will be downloaded from a
        central location. It needs some default config but the webservice it will
        need to connect to will be customer specific, i.e. each client will need to
        connect to their own URL.

        Perhaps this is poor design but it's more secure than allowing all clients
        to connect to a single service. I know I can deserialize/serialize the
        app.config but there must be a preferred way to modify these particular
        settings. I don't want the user to modify the file directly.

        Also it seems like there may be occasions when things like maxBufferSize
        need to be tweaked so an interface of seems like it should be a common
        requirement to me. What do other people do?

        Thanks
        Andrew



        "Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote in
        message news:FBE1F43F-6713-49EA-B21C-58FDD09148E2@mi crosoft.com...
        It's a file, you can read and write it as normal. However, you will
        restart the application. Now, step back a bit. Endpoints are established
        ahead of time and configured accordingly. Your requirement is about the
        same as rewriting a browser url so that clients can hit this new url. Why
        not publish the url ahead of time? Why the strange requirement?
        >
        --
        >
        Regards,
        Alvin Bruney [MVP ASP.NET]
        >
        [Shameless Author plug]
        Download OWC Black Book, 2nd Edition
        Exclusively on www.lulu.com/owc $15.00
        Need a free copy of VSTS 2008 w/ MSDN Premium?

        -------------------------------------------------------
        >
        >
        "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
        news:ODLig9W$IH A.4800@TK2MSFTN GP03.phx.gbl...
        >Hi
        >>
        >How do I programmaticall y change (read/write) the values in this
        >app.config file at runtime? Specifically I want to change the client
        >endpoint address but it would be nice to change other values too. I
        >thought this is what ServiceHost is for but is seems way more complicated
        >to use for what I'm trying to do.
        >>
        > <system.service Model>
        > <bindings>
        > <basicHttpBindi ng>
        > <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
        >openTimeout="0 0:01:00"
        > receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
        >allowCookies=" false"
        > bypassProxyOnLo cal="false"
        >hostNameCompar isonMode="Stron gWildcard"
        > maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
        >maxReceivedMes sageSize="67108 864"
        > messageEncoding ="Text" textEncoding="u tf-8"
        >transferMode=" Buffered"
        > useDefaultWebPr oxy="true">
        > <readerQuotas maxDepth="32" maxStringConten tLength="8192"
        >maxArrayLength ="16384"
        > maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
        > <security mode="None">
        > <transport clientCredentia lType="None"
        >proxyCredentia lType="None"
        > realm="" />
        > <message clientCredentia lType="UserName "
        >algorithmSuite ="Default" />
        > </security>
        > </binding>
        > </basicHttpBindin g>
        > </bindings>
        > <client>
        > <endpoint address="http://webservice.com/Service.asmx"
        > binding="basicH ttpBinding"
        >bindingConfigu ration="DataSer viceSoap"
        > contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
        > </client>
        > </system.serviceM odel>
        >>
        >Many thanks
        >Andrew
        >>

        Comment

        • Jeff Dillon

          #5
          Re: Programmaticall y change web service information in app.config


          "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
          news:uDTEEGe$IH A.4616@TK2MSFTN GP06.phx.gbl...
          OK, this is the situation.
          >
          The windows form client is a ClickOnce app and will be downloaded from a
          central location. It needs some default config but the webservice it will
          need to connect to will be customer specific, i.e. each client will need
          to connect to their own URL.
          >
          Perhaps this is poor design but it's more secure than allowing all clients
          to connect to a single service. I know I can deserialize/serialize the
          app.config but there must be a preferred way to modify these particular
          settings. I don't want the user to modify the file directly.
          >
          Also it seems like there may be occasions when things like maxBufferSize
          need to be tweaked so an interface of seems like it should be a common
          requirement to me. What do other people do?
          >
          Thanks
          Andrew
          >
          >
          >
          "Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote
          in message news:FBE1F43F-6713-49EA-B21C-58FDD09148E2@mi crosoft.com...
          >It's a file, you can read and write it as normal. However, you will
          >restart the application. Now, step back a bit. Endpoints are established
          >ahead of time and configured accordingly. Your requirement is about the
          >same as rewriting a browser url so that clients can hit this new url. Why
          >not publish the url ahead of time? Why the strange requirement?
          >>
          >--
          >>
          >Regards,
          >Alvin Bruney [MVP ASP.NET]
          >>
          >[Shameless Author plug]
          >Download OWC Black Book, 2nd Edition
          >Exclusively on www.lulu.com/owc $15.00
          >Need a free copy of VSTS 2008 w/ MSDN Premium?
          >http://msmvps.com/blogs/alvin/Default.aspx
          >-------------------------------------------------------
          >>
          >>
          >"Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
          >news:ODLig9W$I HA.4800@TK2MSFT NGP03.phx.gbl.. .
          >>Hi
          >>>
          >>How do I programmaticall y change (read/write) the values in this
          >>app.config file at runtime? Specifically I want to change the client
          >>endpoint address but it would be nice to change other values too. I
          >>thought this is what ServiceHost is for but is seems way more
          >>complicated to use for what I'm trying to do.
          >>>
          >> <system.service Model>
          >> <bindings>
          >> <basicHttpBindi ng>
          >> <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
          >>openTimeout=" 00:01:00"
          >> receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
          >>allowCookies= "false"
          >> bypassProxyOnLo cal="false"
          >>hostNameCompa risonMode="Stro ngWildcard"
          >> maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
          >>maxReceivedMe ssageSize="6710 8864"
          >> messageEncoding ="Text" textEncoding="u tf-8"
          >>transferMode= "Buffered"
          >> useDefaultWebPr oxy="true">
          >> <readerQuotas maxDepth="32" maxStringConten tLength="8192"
          >>maxArrayLengt h="16384"
          >> maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
          >> <security mode="None">
          >> <transport clientCredentia lType="None"
          >>proxyCredenti alType="None"
          >> realm="" />
          >> <message clientCredentia lType="UserName "
          >>algorithmSuit e="Default" />
          >> </security>
          >> </binding>
          >> </basicHttpBindin g>
          >> </bindings>
          >> <client>
          >> <endpoint address="http://webservice.com/Service.asmx"
          >> binding="basicH ttpBinding"
          >>bindingConfig uration="DataSe rviceSoap"
          >> contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
          >> </client>
          >> </system.serviceM odel>
          >>>
          >>Many thanks
          >>Andrew
          >>>
          >
          >
          Keep in mind that the web service proxy/client constructor is overloaded and
          can take the endpoint address as a parameter


          Comment

          • Alvin Bruney [ASP.NET MVP]

            #6
            Re: Programmaticall y change web service information in app.config

            OK, this is the situation.
            Yes I suspected that was half the story but I wanted to be polite about it.

            The recommended solution is to define multiple endpoints. Bear in mind, WCF
            is designed to be coded once and configured appropriately in production.
            Things like adding endpoints should not be addressed at the code level, they
            should rightly be handled by support professional 'in production' with no
            touch to the code.

            --

            Regards,
            Alvin Bruney [MVP ASP.NET]

            [Shameless Author plug]
            Download OWC Black Book, 2nd Edition
            Exclusively on www.lulu.com/owc $15.00
            Need a free copy of VSTS 2008 w/ MSDN Premium?

            -------------------------------------------------------


            "Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
            news:uDTEEGe$IH A.4616@TK2MSFTN GP06.phx.gbl...
            OK, this is the situation.
            >
            The windows form client is a ClickOnce app and will be downloaded from a
            central location. It needs some default config but the webservice it will
            need to connect to will be customer specific, i.e. each client will need
            to connect to their own URL.
            >
            Perhaps this is poor design but it's more secure than allowing all clients
            to connect to a single service. I know I can deserialize/serialize the
            app.config but there must be a preferred way to modify these particular
            settings. I don't want the user to modify the file directly.
            >
            Also it seems like there may be occasions when things like maxBufferSize
            need to be tweaked so an interface of seems like it should be a common
            requirement to me. What do other people do?
            >
            Thanks
            Andrew
            >
            >
            >
            "Alvin Bruney [ASP.NET MVP]" <vapor dan using hot male spam filterwrote
            in message news:FBE1F43F-6713-49EA-B21C-58FDD09148E2@mi crosoft.com...
            >It's a file, you can read and write it as normal. However, you will
            >restart the application. Now, step back a bit. Endpoints are established
            >ahead of time and configured accordingly. Your requirement is about the
            >same as rewriting a browser url so that clients can hit this new url. Why
            >not publish the url ahead of time? Why the strange requirement?
            >>
            >--
            >>
            >Regards,
            >Alvin Bruney [MVP ASP.NET]
            >>
            >[Shameless Author plug]
            >Download OWC Black Book, 2nd Edition
            >Exclusively on www.lulu.com/owc $15.00
            >Need a free copy of VSTS 2008 w/ MSDN Premium?
            >http://msmvps.com/blogs/alvin/Default.aspx
            >-------------------------------------------------------
            >>
            >>
            >"Andrew Jocelyn" <j055@newsgroup s.nospamwrote in message
            >news:ODLig9W$I HA.4800@TK2MSFT NGP03.phx.gbl.. .
            >>Hi
            >>>
            >>How do I programmaticall y change (read/write) the values in this
            >>app.config file at runtime? Specifically I want to change the client
            >>endpoint address but it would be nice to change other values too. I
            >>thought this is what ServiceHost is for but is seems way more
            >>complicated to use for what I'm trying to do.
            >>>
            >> <system.service Model>
            >> <bindings>
            >> <basicHttpBindi ng>
            >> <binding name="DataServi ceSoap" closeTimeout="0 0:01:00"
            >>openTimeout=" 00:01:00"
            >> receiveTimeout= "01:00:00" sendTimeout="00 :01:00"
            >>allowCookies= "false"
            >> bypassProxyOnLo cal="false"
            >>hostNameCompa risonMode="Stro ngWildcard"
            >> maxBufferSize=" 67108864" maxBufferPoolSi ze="524288"
            >>maxReceivedMe ssageSize="6710 8864"
            >> messageEncoding ="Text" textEncoding="u tf-8"
            >>transferMode= "Buffered"
            >> useDefaultWebPr oxy="true">
            >> <readerQuotas maxDepth="32" maxStringConten tLength="8192"
            >>maxArrayLengt h="16384"
            >> maxBytesPerRead ="4096" maxNameTableCha rCount="16384" />
            >> <security mode="None">
            >> <transport clientCredentia lType="None"
            >>proxyCredenti alType="None"
            >> realm="" />
            >> <message clientCredentia lType="UserName "
            >>algorithmSuit e="Default" />
            >> </security>
            >> </binding>
            >> </basicHttpBindin g>
            >> </bindings>
            >> <client>
            >> <endpoint address="http://webservice.com/Service.asmx"
            >> binding="basicH ttpBinding"
            >>bindingConfig uration="DataSe rviceSoap"
            >> contract="MySer vice.DataServic eSoap" name="DataServi ceSoap" />
            >> </client>
            >> </system.serviceM odel>
            >>>
            >>Many thanks
            >>Andrew
            >>>
            >
            >

            Comment

            • Andrew Jocelyn

              #7
              Re: Programmaticall y change web service information in app.config


              Thanks Jeff
              >
              Keep in mind that the web service proxy/client constructor is overloaded
              and can take the endpoint address as a parameter
              >
              That's the answer I was looking for. For now anyway.

              Andrew


              Comment

              Working...