简体   繁体   English

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

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

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. 但是当我指定<endpoint address="/myAddress" binding="basicHttpBinding" contract="Wcf.Contracts.IPublicService"/> myAddress将被忽略。 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. 换句话说,我希望它创建我的服务端点,就像这个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? 我已经google了,发现在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>

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 . 假设您的服务的基地址是http://localhost:1111/PublicService.svc ,指定address="/myAddress"属性将导致该端点的地址变为http://localhost:1111/PublicService.svc/myAddress The endpoint's relative path comes after the service address. 端点的相对路径来服务地址

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 this good tutorial, I just did it a few days ago... 你可以按照这个好的教程,我几天前做的...

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM