是否可以在运行时动态地将命名空间更改为ServiceContract?

Win*_*Guy 6 .net c# wcf

例如:

[ServiceContract(Namespace = "@services.url@/",
        Name = "FedExContract")]
Run Code Online (Sandbox Code Playgroud)

我需要在运行时更改"@ services.url @"的值.

Bek*_*pov 0

除了使用条件编译符号之外想不出其他方法,即

#if Debug 
[ServiceContract(Namespace = "@AA.BBB@/", Name = "FedExContract")]

#endif 
Run Code Online (Sandbox Code Playgroud)

命名空间应该是静态的,因为如果更改合约的命名空间,您可能需要重新创建客户端代理。