2012-05-31 36 views
3

我有basicHttpBindings簡單的wcf服務,並希望在IIS上承載它。如何指定IIS上託管的WCF服務的端點地址?

但是當我指定 <endpoint address="/myAddress" binding="basicHttpBinding" contract="Wcf.Contracts.IPublicService"/> myAddress被忽略。換句話說,我期待它創建我的服務端點,像這個localhost:1111/myaddress/PublicService.svc,但它只是通過組合localhost和PublicService.svc - localhost:1111/publicservice.svc來創建端點。

爲什麼我需要? 我有一些其他的服務託管在項目中,並希望在localhost後用不同的URL創建它們(我不想將它們移動到不同的文件夾中)。

我已經使用Google搜索並發現在IIS上託管時主機基地址被忽略,這對於端點地址也是如此嗎?

在此先感謝

<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> 
+1

如果您將服務放在名爲「myAddress」的文件夾中,路徑將從/PublicService.svc - > /myAddress/PublicService.svc更​​改。如果你想將它們全部存儲在一個地方,但不同的路徑,你應該看看添加ServiceRoutes。 – Zachary

+0

但爲什麼我們需要端點地址,如果它不能「適當」使用?他們只用於Windows服務中的自我託管服務嗎? – Lev

回答

11

假設你的服務的基址是http://localhost:1111/PublicService.svc,指定address="/myAddress"屬性將導致該端點的地址,成爲http://localhost:1111/PublicService.svc/myAddress。服務地址爲後端點的相對路徑爲

2

我認爲你的問題可能是這樣的Service.svc文件...

打開它並修改單行中這樣說:

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

您可以按照this好的教程,我剛剛做了幾天...

希望它有幫助!