views:

74

answers:

3

Currently we're using in code <System.Web.Services.WebService(Namespace:="https://ourservice/")&gt; to set the namespace, can this be done in web.config, instead? I've looked but can't find where?

VS2008, ASMX web service.

A: 

have you tried this?

 <Services>
    <asp:ServiceReference
       path="https://ourservice" />
  </Services>

another option may be to create pair in the web.config file and read that section using ConfigurationManager class.

<appSettings>
      <add key="OurService" 
      value="https://ourservice"/&gt;
</appSettings>
baskint
This is an ASMX web service, not aspx page, so it will have to be an entry in a config file.
Jim
A: 

I don't think you can put it in the config file (though I never bothered to check).

If you just want it stored at a central location, you can use always use a constant:

internal sealed class ServiceConstants {
   internal const string Namespace = "urn:example.com/~coolest/service/ever";
} 
[ServiceContract(Namespace=ServiceConstants.Namespace)]
[WebService(Namespace=ServiceConstants.Namespace)]
public sealed class MyService {}
Thanks, but don't want to need to change code and recompile when moving to diff location.
Jim
+4  A: 

The most important question hasn't been asked: why do you think you want to do this.

Most people who ask this question are under the impression that the namespace is related to the URL at which the service is deployed. They have nothing at all to do with each other. In fact, the namespace could be a URI like "urn:services.yourcompany.com", which is clearly not a location on the Internet.

John Saunders
Thanks, but I'm stuck because the web service consumer is already configured for this. We have 1 setting for QA and another for Prod. I'm hoping to be able to remove this completely, but just in case, was looking for a better way to handle this than changing code and recompiling. If it's not possible, then I'll have more ammo for removing it.
Jim
@Jim: you should point them at this question. They've made a significant mistake. The don't understand namespaces. They are not meant to change between one environment and another. They are not meant to be locations in the Internet.
John Saunders
@John Saunders: Thanks, that's what I needed.
Jim