Bonjour à tous,

J'ai développé un programme qui va se connecter à un WebService de test.

Mais le programme doit pouvoir gérer des URL de WebServices différents (les WS seront à chaque fois identiques, mais seules les URL changeront).
Comment puis-je faire ceci ?

Actuellement, dans mon code, j'ai recherché où je retrouvais l'adresse URL de mon serveur de test, et je la trouve ici :

Dans Settings.Designer :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
<Global.System.Configuration.ApplicationScopedSettingAttribute(),  _
         Global.System.Diagnostics.DebuggerNonUserCodeAttribute(),  _
         Global.System.Configuration.SpecialSettingAttribute(Global.System.Configuration.SpecialSetting.WebServiceUrl),  _
         Global.System.Configuration.DefaultSettingValueAttribute("http://12.123.12.136:2002/AnbExportService")>  _
        Public ReadOnly Property TOTO_WS_AnbExportService() As String
            Get
                Return CType(Me("TOTO_WS_AnbExportService"),String)
            End Get
        End Property
Et dans Setting.settings :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="My" GeneratedClassName="MySettings" UseMySettingsClassName="true">
  <Profiles />
  <Settings>
    <Setting Name="TOTO_WS_AnbExportService" Type="(Web Service URL)" Scope="Application">
      <Value Profile="(Default)">http://12.123.12.136:2002/AnbExportService</Value>
    </Setting>
  </Settings>
</SettingsFile>
Et dans app.config :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
<applicationSettings>
        <Mercure.My.MySettings>
            <setting name="TOTO_WS_AnbExportService" serializeAs="String">
                <value>http://12.123.12.136:2002/AnbExportService</value>
            </setting>
        </Mercure.My.MySettings>
    </applicationSettings>
Et dans Reference.map :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
<DiscoveryClientResultsFile xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Results>
    <DiscoveryClientResult referenceType="System.Web.Services.Discovery.ContractReference" url="http://12.123.12.136:2002/AnbExportService?wsdl" filename="AnbExportService.wsdl" />
    <DiscoveryClientResult referenceType="System.Web.Services.Discovery.SchemaReference" url="http://12.123.12.136:2002/AnbExportService?xsd=1" filename="AnbExportService.xsd" />
  </Results>
</DiscoveryClientResultsFile>
Et dans AnbExportService.wsdl :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
<types>
    <xsd:schema>
      <xsd:import schemaLocation="http://12.123.12.136:2002/AnbExportService?xsd=1" namespace="http://toto-solutions.fr/anb" />
    </xsd:schema>
  </types>
(...)
<service name="AnbExportService">
    <port name="AnbExportServicePort" binding="tns:AnbExportServicePortBinding">
      <soap:address location="http://12.123.12.136:2002/AnbExportService" />
    </port>
  </service>
(note : l'URL a bien sûr été changée dans ces extraits de code).

Donc, comment puis-je faire pour passer l'URL et le port en paramètre de l'application, pour que chaque utilisateur accède à son WS propre ?

Merci d'avance.