C#: square bracket alternative / a class for multiple SOAP addresses
<p>I've generated a SOAP class using <code>wsdl.exe</code> tool. Unfortunately, it seems to be bound to a specific URL and I need to be able to change it on per-instance basis (I'd like to be able to connect to multiple URLs that share the same interface). So, I'd like to change such code:</p>

<pre><code>/// &lt;remarks/&gt;
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://productmarket.bigbrain.math.uni.lodz.pl/")]
public partial class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol {

// some code here

    /// &lt;remarks/&gt;
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://productmarket.bigbrain.math.uni.lodz.pl/Authenticate", RequestNamespace="http://productmarket.bigbrain.math.uni.lodz.pl/", ResponseNamespace="http://productmarket.bigbrain.math.uni.lodz.pl/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public bool Authenticate(int ContractorId, string Password) {
        object[] results = this.Invoke("Authenticate", new object[] {
                    ContractorId,
                    Password});
        return ((bool)(results[0]));
    }

// more code here

}
</code></pre>

<p>So that the attributes from Authenticate (the ones with HTTP URL's) are variable. The only solution I've found so far is to make a static string inside of Service1 class and change the Authenticate code like that:</p>

<pre><code>/// &lt;remarks/&gt;
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.3038")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="Service1Soap", Namespace="http://productmarket.bigbrain.math.uni.lodz.pl/")]
public partial class Service1 : System.Web.Services.Protocols.SoapHttpClientProtocol {


//some code

    public static string prefix = "http://productmarket.bigbrain.math.uni.lodz.pl/";
    public static string soap_namespace = "http://productmarket.bigbrain.math.uni.lodz.pl/";


    /// &lt;remarks/&gt;
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute(Service1.prefix+"Authenticate", RequestNamespace=Service1.soap_namespace, ResponseNamespace=Service1.soap_namespace, Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public bool Authenticate(int ContractorId, string Password) {
        object[] results = this.Invoke("Authenticate", new object[] {
                    ContractorId,
                    Password});
        return ((bool)(results[0]));
    }

//some code

}
</code></pre>

<p>Is there a better solution that would pull this info from instances instead of forcing me to change them every request? I must admit I don't exactly understand the concept of attributes in C#.</p>
