C# 如何为 IIS 上托管的 WCF 服务指定端点地址?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10838985/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 15:29:06  来源:igfitidea点击:

how to specify endpoint address for WCF service hosted on IIS?

c#.netwcf

提问by Lev

I have simple wcf service with basicHttpBindings and want to host it on IIS.

我有一个带有 basicHttpBindings 的简单 wcf 服务,并希望将它托管在 IIS 上。

but when I'm specifying <endpoint address="/myAddress" binding="basicHttpBinding" contract="Wcf.Contracts.IPublicService"/>myAddress is ignored. In other words I'm expecting it creates my service endpoint sth like this localhost:1111/myaddress/PublicService.svc, but it creates endpoint simply by combining localhost and PublicService.svc - localhost:1111/publicservice.svc.

但是当我指定 <endpoint address="/myAddress" binding="basicHttpBinding" contract="Wcf.Contracts.IPublicService"/>myAddress 时被忽略。换句话说,我希望它像这样 localhost:1111/myaddress/PublicService.svc 一样创建我的服务端点,但它只是通过组合 localhost 和 PublicService.svc - localhost:1111/publicservice.svc 来创建端点。

why I need? I have some other services hosted in project and want to create each of them with different url after localhost.(I don't want to move them to different folder).

为什么我需要?我在项目中托管了一些其他服务,并希望在 localhost 之后使用不同的 url 创建它们中的每一个。(我不想将它们移动到不同的文件夹)。

I've googled and discovered that host base address is ignored when hosting on IIS, is this true for endpoint addresse too?

我用谷歌搜索并发现在 IIS 上托管时主机基地址被忽略,端点地址也是如此吗?

thanks in advance

提前致谢

<service name="Wcf.Services.AdminService">
    <endpoint address="/address" binding ="basicHttpBinding" contract="Wcf.Contracts.IAdminService"/>
    <endpoint address="mex" binding ="mexHttpBinding" contract="IMetadataExchange"/>
  </service>
  <service name="Wcf.Services.PublicService">
    <endpoint address="/address1" binding="basicHttpBinding" contract="Wcf.Contracts.IPublicService"/>
    <endpoint address="mex" binding="basicHttpBinding" contract="IMetadataExchange"/>
  </service>

采纳答案by Douglas

Assuming the base address of your service is http://localhost:1111/PublicService.svc, specifying the address="/myAddress"attribute would cause that endpoint's address to become http://localhost:1111/PublicService.svc/myAddress. The endpoint's relative path comes afterthe service address.

假设您的服务的基地址是http://localhost:1111/PublicService.svc,则指定该address="/myAddress"属性将导致该端点的地址变为http://localhost:1111/PublicService.svc/myAddress。端点的相对路径服务地址之后。

回答by Luis

I think your problem might be something like in the Service.svc file...

我认为您的问题可能类似于 Service.svc 文件...

Open it and modify the single line in it like this:

打开它并像这样修改其中的单行:

<%@ ServiceHost Language="C#" Debug="true" Service="Wcf.Services.PublicService" %>

You can follow thisgood tutorial, I just did it a few days ago...

你可以按照这个很好的教程,我几天前才做的......

Hope it helps!

希望能帮助到你!