views:

118

answers:

1

I've got an ASMX webservice as a separate project in Visual Studio 2005. In pursuit of "assembly separation" per a CODE Magazine tutorial, my proxy class is in a separate class library project containing no code of mine - just a web reference named ASMXproxy with the associated reference.cs, app.config, .disco and .wsdl files. Thus, when compiled I have a FileServiceProxy.dll.

For consuming this WS, I have a web app project called FileServiceDemo in this same solution. It has no web reference but instead a "regular" reference to FileServiceProxy.dll. In my default.aspx.cs file, I gain access to my WS via these snippets:

using FileServiceProxy.ASMXproxy;
public partial class _Default : System.Web.UI.Page
{
    ASMXproxy.FileService brokerService;
protected void Page_Load(object sender, EventArgs e)
{
    try
        {
            brokerService = new ASMXproxy.FileService();

So while things work OK this way, I find it awkward when I want to test a deployed version or make changes to a "localhost" version. I can't simply make changes to the app.config:

<applicationSettings>
    <FileServiceProxy.Properties.Settings>
        <setting name="FileServiceProxy_ASMXproxy_FileService" serializeAs="String">
            <value>http://localhost/TRIMBrokerService/FileService.asmx&lt;/value&gt;
        </setting>
    </FileServiceProxy.Properties.Settings>
</applicationSettings>

In short, when I need to publish my web app to another server, I have to change the web reference in proxy class and rebuild it. Then when I want to debug it on my localhost, I have to change the web reference back to localhost (as above).

Ideally, I would like to expose some sort of choice (e.g. radio buttons or a textbox for altering a URL at runtime) in my web app demo project such that I could have a "late binding" of sorts for the desired FileServiceProxy.dll to be used at runtime. Others have sketched proposals "using config files" but I am stuck on how to do that. It appears to me that I would have to have an additional project and hence another DLL - perhaps FileServiceProxyPROD.dll - but this seems awkward and even then I'm not sure what else I'd have to do.

+1  A: 

Actually, you can use the same reference. Just change the Url property of the proxy instance:

using (var svc = new WebServiceProxy())
{
    svc.Url = realUrl;
    var result = svc.ServiceMethod();
}
John Saunders
Thanks John. This is neat; I see what you mean now.
John Galt