2015-09-07 36 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

欢迎您。谢谢。 –