wcf - 如何根据Restfull wcf服务中的暂存环境更改uritemplate
问题描述
我的非产品环境有以下运营合同
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "members/Empdata")]
但我需要uritemplate
为我的 prod 环境更改它,如下所示
[OperationContract]
[WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "members/Empdata/Search")]
我尝试了很多东西都没有成功
我试图把钥匙放进去web.config
,但界面不允许接受任何来自配置的东西。
解决方案
您只能在编译时处理这个,而不是在运行时。
我真的希望暂存和生产环境确实允许针对公共根目录使用相同的 url 结构。它们是合同的一部分。
如果你真的想在代码中解决这个问题,那么你可以使用编译器指令,并通过提供正确的编译参数来控制代码中的两个变体。
[OperationContract]
#if STAGING
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "members/Empdata")]
#endif
#if PRODUCTION
[WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "members/Empdata/Search")]
#endif
public string Search(string data)
现在,您需要确保已为 Staging 和 Production 构建配置,并为每个配置设置正确的条件编译符号。
推荐阅读
- corda - Corda:如何在 valult DB 中将即时状态变量保存为 UTC?
- r - rbind(x, y) 与 rbind(y, x)
- javascript - 检索 CSS 生成的内容
- nginx-reverse-proxy - 设置 Docker 存储库端口
- azure-functions - Microsoft.Azure.WebJobs.Host 出现默认持久函数错误:无法绑定参数“starter”
- c# - 从联系表发送电子邮件
- data-science-experience - 数据精炼作业失败并出现 SCAPIException CDICO2060E
- r - 如何使用 dplyr 过滤数据以一起检索 NA 和另一个值?
- openid - 将新端点添加到 OpenID 配置到 Auth0 应用程序?
- javascript - Blob 到 base64 ReactJs