Search code examples
c#web-servicessoapwsdlasmx

How does a web reference know what address to use?


I have to make a call to a web service from inside a new C# class library project. The web service is not accessible to me yet (different geographic location and closed network until release). I do have the WSDL for it however and have added a Web Reference in my new class library project to the WSDL.

My problem here is that I do not see where I can configure the service address that the WSDL is based on. It's fine developing against the WSDL stub for now, but when I release it to the other development centre, they will need to be able to set the correct address for their service so that my service call into it works.

Is there a common practice here? i.e. a config file entry that I can add or something?


Solution

  • If you added the web reference using VS, it will automatically creating a corresponding setting in your .config file.

    You can also view / modify this in Settings.settings.

    N.B. by default VS sets this setting to generate a default value (which is based on the original value you use to add the reference, I believe and it gets buried somewhere in a generated code file). You can disable this by viewing the project's Properties --> Settings, highlighting the WSDL setting and then in the Properties tab (docked window) set GenerateDefaultValueInCode = False.

    Once deployed, the WSDL location can be updated by modifying the relevant .config file value.


    EDIT: the Web Reference URL Behaviour property should be set to Dynamic.