WCF:我需要将“http://tempuri.org/”替换为“http://tempuri.org/”吗?使用动态名称空间?
我有一个将部署到多个域的 Web 服务。我想摆脱 WCF 默认命名空间“http://tempuri.org/”并替换它与部署 Web 服务的域一起使用,例如“http://mydomain.com/”。我知道这里最好的解决方案就是让 Web 服务存在于一个地方,并使用该域作为命名空间,但目前这对我来说不是一个选择。
我在此处找到了此问题的部分答案。在这篇文章中,建议的答案是在配置文件中设置 URL 属性,但恐怕我不太明白答案。这个 URL 属性到底在哪里?此外,由于我无法控制的原因,将使用此 Web 服务的客户端应用程序没有 app.config 文件,因此该客户端应用程序中的所有配置都必须在代码中设置。我不确定这是否重要,但我想我会提到它,以防万一。
编辑:为了澄清,我试图删除的对“http://tempuri.org”的引用位于svcutil.exe 生成的 .cs 文件。
例如
[System.ServiceModel.OperationContractAttribute(Action = "http://tempuri.org/IEmailService/SendEmail", ReplyAction = "http://tempuri.org/IEmailService/SendEmailResponse")]
void SendEmail(Services.Internal.CorrespondenceWebService.Email email);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会将 XML 名称空间与 URL 混淆。下面是一个不是 URL 的命名空间示例:
urn:schemas-microsoft-com:datatypes
。由于命名空间不一定是 URL,因此您不必为每个环境更改它。
另一方面,您应该选择一个命名空间,并一致地使用它。也许类似
http://services.mydepartment.mycompany.com/myservice/
。您确实不想发布仍然使用http://tempuri.org/
的服务,因为这表明您缺乏对命名空间的理解。回答您更新的问题:这些命名空间存在于 svcutil.exe 生成的 .cs 文件中,因为它们存在于服务的元数据中。您需要在服务中更改它们,并且当创建或更新客户端时,它将具有正确的命名空间。
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 useshttp://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.