为什么WCF服务代理flie包含http://tempuri.org?

Why does WCF service proxy flie contain http://tempuri.org?

我正在学习制作基本的 WCF 服务。该服务在控制台应用程序中运行。客户端也是同一台计算机上的控制台应用程序。我正在使用 netTCP 绑定。

我使用 SvcUtil.exe 生成代理 class 文件,虽然一切正常并按我预期的方式运行,但我对代理 class 文件部分感到困惑:

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="IService1")]
public interface IService1
{

    [System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IService1/myFunction", ReplyAction="http://tempuri.org/IService1/myFunctionResponse")]
    string[] myFunction();

}

什么是http://tempuri.org/IService1/myFunction?对于像我这样的新手,这似乎是一个网址。我不明白这部分程序在做什么以及为什么有必要。 svcutil.exe 是否在网上放置了我的程序所需的任何信息?我迷路了。

this seems like a web address.

这不完全是一个网址。它是一个命名空间。您需要做的就是确保它是独一无二的。

I don't understand what this part of the program is doing and why it's necessary.

需要命名空间。它构成您服务行为合同的一部分。

Did svcutil.exe place any info required for my program on the web?

不,除了您自己的代码之外,您的程序没有任何内容。您的程序可以运行完全离线。

背景

每个 Web 服务都需要一个唯一的命名空间,以便与其他服务区分开来。万维网联盟建议为命名空间使用 URI,因为 URI 保证在全球范围内是唯一的,并且您可能有一个用于您的 Web 服务的域。

Microsoft 使用 tempuri.org 作为使用 Visual Studio 创建的 Web 服务的默认值。它代表临时统一资源标识符,Microsoft 拥有该域。它仅用于提供占位符,必须替换,尤其是对于开放网络上的服务。

在您的情况下,由于您可能没有该服务的域,您可以使用假域,只要确保它是唯一的即可。从技术上讲,它可以是任何东西,不一定是 URI,但为了保持一致性,建议是 URI。此外,它只需要在您的网络上是唯一的,这就是为什么即使是默认的 tempuri.org 也能很好地工作,但最好尝试想出一个全球唯一的假域名。