4

I have a web service that will be deployed to multiple domains. I would like to get rid of the WCF default namespace of "http://tempuri.org/," and replace it with the domain on which the web service is deployed, such as "http://mydomain.com/." I know the best solution here is simply to have the web service exist in one place, and use that one domain as the namespace, but that is not an option for me at the moment.

I found a partial answer to this question here. In this post, the suggested answer is to set a URL property in the config file, but I am afraid I don't quite understand the answer. Where is this URL property, exactly? Also, for reasons beyond my control, the client app that will be consuming this web service does not have an app.config file, so all configs in that client app will have to be set in code. I am not sure if that matters, but figured I would mention it, just in case.

EDIT: To clarify, the reference to "http://tempuri.org" that I am trying to remove is inside the .cs file that is generated by svcutil.exe.

e.g.

[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IEmailService/SendEmail", ReplyAction = "http://tempuri.org/IEmailService/SendEmailResponse")]
void SendEmail(Services.Internal.CorrespondenceWebService.Email email);
Community
  • 1
  • 1
campbelt
  • 1,573
  • 5
  • 27
  • 43
  • http://stackoverflow.com/questions/2397519/programmatically-add-an-attribute-to-a-method-or-parameter -- that of any help? Assign it later on? From what I'm reading, `GetCustomAttributes` returns a clone of the attribute applied so you can't modify it. – Brad Christie Feb 24 '11 at 18:09
  • 2
    Why do you need changing namespaces? It is just a naming container. – Ladislav Mrnka Feb 24 '11 at 18:09
  • Also found this on MSDN: http://social.msdn.microsoft.com/forums/en-US/wcf/thread/5573326a-21b3-4d21-b05c-8e00b1674137/ – Brad Christie Feb 24 '11 at 18:11
  • Thanks, guys. I want to change name spaces in order to attempt to follow best practices I've read about. I'll review those links and see where they take me. – campbelt Feb 25 '11 at 20:33
  • 1
    It's a best practice to not use tempuri.org. It's not a best practice to change the namespace for every deployment. – John Saunders Feb 25 '11 at 20:49

1 Answers1

7

You may be confusing XML namespaces with URLs. Here's an example of a namespace which is not a URL: urn:schemas-microsoft-com:datatypes.

Since a namespace is not necessarily a URL, you do not have to change it for each environment.

On the other hand, you should pick a namespace, and use it consistently. Perhaps something like http://services.mydepartment.mycompany.com/myservice/. You really don't want to ship a service that still uses http://tempuri.org/, as that demonstrates a lack of understanding of namespaces.


In response to your updated question: those namespaces are present in the .cs file generated by svcutil.exe because they are present in the metadata from the service. You need to change them in the service, and when the client is created or updated, it will have the correct namespaces.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Yeah, I think it's clear that I'm confused :) I understand namespaces well enough, I think. I guess the trouble I'm having is knowing exactly where in WCF web service code to set the thing. I've been trying, and I know I'm changing the wrong values because after I change the values, I end up getting errors related to the web service files not being found. – campbelt Feb 25 '11 at 20:36
  • 2
    Try `[ServiceContract(Namespace="http://services.mydepartment.mycompany.com/myservice/")]` – John Saunders Feb 25 '11 at 20:41
  • Thank you. Just to clarify, I added an edit to my original post, describing the reference to "http://tempuri.org" that I am trying to change. I probably should have included that in the first place, but it didn't occur to me at the time. – campbelt Feb 25 '11 at 20:49
  • Not to "get on your case", but just to try to understand: you thought we'd know which "tempuri.org" you were referring to, and that there was a way to change it, but that you had just missed it. Is that accurate? I'm trying to learn what it is that _I'm_ taking for granted in writing about namespaces. – John Saunders Feb 25 '11 at 20:52
  • I don't know if tempuri.org shows up anywhere other than in that generated .cs file, but as I read through these responses, I started to think that there might be other places. So, I just wanted to avoid ambiguity if possible. – campbelt Feb 25 '11 at 21:09
  • 1
    I now understand what I was doing wrong, and why I was confused. I added a namespace to my ServiceContract, my ServiceBehavior, and my DataContract, which effectively got rid of the tempuri. BUT, I had forgotten to update references to my classes in the client, so that they referred to the new namespace. So, this boils down to a really simple mistake made by a newbie under too much pressure :) – campbelt Feb 25 '11 at 21:13
  • The namespaces show up in the metadata, which is what is used to create those client classes. – John Saunders Feb 26 '11 at 00:43