gpt4 book ai didi

.net - ServiceHost和WebServiceHost有什么区别?

转载 作者:行者123 更新时间:2023-12-04 07:11:52 27 4
gpt4 key购买 nike

对于.Net4,以下内容之间是否有区别

Uri baseAddress = new Uri("http://localhost:8080/test");
ServiceHost host = new ServiceHost(typeof(TestService), baseAddress);
host.Open();


Uri baseAddress = new Uri("http://localhost:8080/test");
WebServiceHost host = new WebServiceHost(typeof(TestService), baseAddress);
host.Open();

所有书籍都建议使用webServiceHost,但是为什么看不到差异?

最佳答案

WebServiceHost类基于ServiceHost类。

默认情况下,它带有WebHttpBindingWebHttpBehavior。 (很好的事情是,您无需使用配置文件即可简单使用。)

MSDN:

When you use WebServiceHost instead of ServiceHost, it will automatically create a Web endpoint for you using the base HTTP address and configure the injected endpoint with the WebHttpBehavior

关于.net - ServiceHost和WebServiceHost有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12881238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com