Change Web Service URL in App.Config

I have a small sharepoint project that integrates into a larger sharepoint project. My project uses two web services. I added them using Web Reference(built-in to the Service Reference dialog box) in VS2010. We have two sets of web services: one for testing and one for production. When I deploy the application locally, the web service settings are written to the web.config file located C:\inetpub\wwwroot\wss\VirtualDirectories\80\on my local machine. The section looks something like this:

 <applicationSettings>
    <XXX.YYY.Properties.Settings>
      <setting name="XXX_YYY_ZZZ_WS1" serializeAs="String">
        <value>http://<TEST_IPAddress>/WebService/WS1.asmx</value>
      </setting>
      <setting name="XXX_YYY_ZZZ_WS2" serializeAs="String">
        <value>http://<TEST_IPAddress>/WebService/WS2.asmx</value>
      </setting>
    </XXX.YYY.Properties.Settings>
  </applicationSettings>

The difference between test and production web services is just the IP address. When I change the IP address to production, the application does not use the new values. I had to go back to VS, update Web Reference URLthe dialog box Propertiesto the correct production URLs, and then deploy the package again. This is tedious as I constantly switch from test to url web service. I want to be able to change the IP address in app.config, refresh the page in the browser and get new URLs.

Am I doing something wrong? Is there any other way to do this?

+3
source share
2 answers

I think that if you change the webservice url in your code, you won’t have to repeat the build process. you can change that

WebServiceObjectName webService = new WebServiceObjectName (); 
webService.Uri = [IPaddress or DNS name]
+1

:

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IPublicWS"
                openTimeout="00:00:05"
                sendTimeout="00:03:00"
                receiveTimeout="00:10:00"
                closeTimeout="00:00:30"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="262144" maxBufferPoolSize="524288" maxReceivedMessageSize="262144"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
              <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="131072" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
              <security mode="None">
                <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                <message clientCredentialType="UserName" algorithmSuite="Default" />
              </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <client>
        <!-- Production -->
        <endpoint name="SvLive" address="http://sv.com/PublicWS/PublicWS.svc/PublicWS" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicWS" contract="SV.IPublicWS" />

        <!-- Test -->
        <endpoint name="SvTest" address="http://staging.sv.com/PublicWS/PublicWS.svc/PublicWS" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPublicWS" contract="SV.IPublicWS" />
    </client>
</system.serviceModel>

, -:

public static PublicWSClient Client()
{
#if PRODUCTION
    return new PublicWSClient("SvLive");
#else
    return new PublicWSClient("SvTest");
#endif
}

:

var sv = PublicWSClient.Client();

, , .

0

All Articles