已提供基地址时 WCF 服务端点的相对地址
我也在学习 WCF,并且是 Web 服务的新手,并且有一个非常基本的问题。请纵容我吧!我正在使用的书中的示例(学习 WCF)创建了一个 ServiceHost 实例,指定服务的基地址(new Uri("http://localhost:8000/HelloIndigo)),我猜这是该类的位置然后,使用最后一个参数(即相对地址)调用 AddServiceEndpoint(),后者只不过是类的名称(可以在库)实际上实现了服务契约?(所讨论的类确实具有该名称。)但是该参数被称为“地址”,这让我非常困惑。
I too am learning WCF and am new to Web Services and have a very basic question. Please indulge me! The example in the book I'm using (Learning WCF) created a ServiceHost instance specifying a base address for the service (new Uri("http://localhost:8000/HelloIndigo)), which I guess is the location of the class library implementing the service. Then a call to AddServiceEndpoint() is done with the final argument, the relative address, given as "HelloIndigoService". Is the latter nothing more than the name of the class (to be found in the library) that actually implements the service contract? (The class in question DOES bear that name.) Yet that argument is called the "address" which is mightily confusing me. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您是自托管,则可以
完整、明确的端点地址,例如
因此您的端点定义了完整的 HTTP 地址
或者:
因此,在您的情况下,基地址是 http://localhost:8000/HelloIndigo - 因此所有服务端点都将位于该地址“下方”。
该端点定义了
HelloIndigoService
的相对地址,因此将这两个地址放在一起,最终的完整地址将是:这适用于自托管ServiceHost 类并打开它以供使用的主机应用程序时)。
当您使用 IIS 托管服务时,不会使用/不会解释基地址 - 相反,
*.svc
文件所在的虚拟目录(在 IIS 中)定义了服务端点的地址。If you're self-hosting, you can have either:
complete, explicit endpoint addresses in your endpoints, e.g.
So your endpoint defines a complete HTTP address
OR:
So in your case, the base address is
http://localhost:8000/HelloIndigo
- so all service endpoints will be "under" that address.The endpoint defines a relative address of
HelloIndigoService
, so those two are put together and the full address in the end will be:This works for self-hosting only (when you have a host application that creates the
ServiceHost
class and opens it for use).When you use IIS to host your service, then the base address is not used / not interpreted - instead, the virtual directory (in IIS) where your
*.svc
file exists defines your service endpoint's address.