2015-09-07 34 views
0

我正在創建這個WCF,但我遇到了我的WCF的ABC這個問題。WCF端點將不會註冊

在我App.Config中我有以下幾點:

<service name="WCFService.AuctionService"> 
    <endpoint address="" binding="basicHttpBinding" contract="WCFService.IAuctionService"> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="" binding="basicHttpBinding" contract="WCFService.IArtPieceService"> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8733/Design_Time_Addresses/WCFService/AuctionService/"/> 
     <add baseAddress="http://localhost:8733/Design_Time_Addresses/WCFService/ArtPieceService/"/> 
     </baseAddresses> 
    </host> 
    </service> 
</services> 

以上是app.config文件的更新版本。

然後它不會運行。 它給我一個未定義的端點。 服務未在合同列表中找到。

以下是我的課:

public class AuctionService : IAuctionService { 
    private AuctionDb _ctr = new AuctionDb(); 

    public void Add(Auction auction) { 
     String regName = "^[a - zA - Z0 - 9]{ 4,10}$"; 

     if (Regex.IsMatch(auction.AuctionName, regName) || auction.AuctionName.Length > 1) 
      throw new ArgumentException(); 
     if(auction.LotDuration.TotalSeconds > 0 || auction.LotDuration.TotalMinutes > 120 || auction.Lots.Count > 0) 
      throw new ArgumentException(); 

     _ctr.Add(auction); 
    } 

    public void Update(Auction auction) { 
     String regName = "^[a - zA - Z0 - 9]{ 4,10}$"; 
     if (Regex.IsMatch(auction.AuctionName, regName) || auction.AuctionName.Length > 1) 
      throw new ArgumentException(); 
     if (auction.LotDuration.TotalSeconds > 0 || auction.LotDuration.TotalMinutes > 120 || auction.Lots.Count > 0) 
      throw new ArgumentException(); 

     _ctr.Update(auction); 
    } 

    public List<Auction> GetAll() { 
     return _ctr.GetAll(); 
    } 
} 

public class ArtPieceService : IArtPieceService 
{ 
    public void Add(ArtPiece piece) 
    { 
     throw new NotImplementedException(); 
    } 
} 

以下是我的ServiceContracts:

[ServiceContract] 
public interface IArtPieceService 
{ 
    [OperationContract] 
    void Add(ArtPiece piece); 
} 

而其他合同:

[ServiceContract] 
public interface IAuctionService 
{ 
    [OperationContract] 
    void Add(Auction auction); 
    [OperationContract] 
    void Update(Auction auction); 

    [OperationContract] 
    List<Auction> GetAll(); 
} 

我的ArtPieceService給沒有定義端點合同名單上沒有合同。

前面感謝您的幫助。

+1

兩個端點不能具有相同的地址 –

+0

每個綁定只能定義一個端點。 –

+0

嘗試在兩個端點的「地址」屬性上使用不同的值 –

回答

2

兩個端點不能有相同的地址。

當您添加以下端點,而不是使用這樣的:

<endpoint address="" binding="basicHttpBinding" contract="WCFService.IArtPieceService"/> 

指定這樣的新地址:

<endpoint address="service2" binding="basicHttpBinding" contract="WCFService.IArtPieceService"/> 

這意味着,當你訪問的第二個端點,您需要使用以下網址:

http://localhost:8733/Design_Time_Addresses/WCFService/AuctionService/service2 

這當然假設您的AuctionService類同時實現IAuctionService和IArtPieceService合同(接口)

如果你想有兩個不同服務兩個不同的類,然後你要創建的app.config另一service XML元素。

這會導致您在services元素中有兩個service元素作爲子元素。

這個新元素是原始元素的副本,但具有不同的名稱和不同的地址以及不同的合同。像這樣:

<service name="WCFService.ArtPieceService"> 
    <endpoint address="" binding="basicHttpBinding" contract="WCFService.IArtPieceService"> 
     <identity> 
     <dns value="localhost"/> 
     </identity> 
    </endpoint> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8733/Design_Time_Addresses/WCFService/ArtPieceService/"/> 
     </baseAddresses> 
    </host> 
    </service> 

此外,請確保您爲兩個服務打開單獨的ServiceHost實例。

+0

查看新的更新 – McBoman

+0

只需用新鮮的眼睛閱讀此消息,以體會它是值得的金;)感謝您的幫助 – McBoman

+0

歡迎您。謝謝。 –