1

我正在尝试在同一基本 URL 上的 IIS 下运行多个 WCF 服务(因此我的项目有多个 .svc 文件)。当我只有一项服务时,一切正常,但当我添加其他服务时,问题就来了。当我尝试访问任何这些附加服务时,客户似乎认为该合同是“IMerchantService”合同。例如,如果我浏览到http://merchants.localtest.me/MerchantProductService.svc?wsdl(本地托管服务的地址),则返回的服务定义是 IMerchantService 而不是 IMerchantProductService。此外,当我浏览到http://merchants.localtest.me/MerchantProductService.svc时,标题是“MerchantService”,而不是我所期望的“MerchantProductService”。

我的服务配置如下:

  <services>
  <service name="MyCompany.Services.Merchants.MerchantProductService">
    <endpoint address="" behaviorConfiguration="Proto.Common.EndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Common" contract="MyCompany.Api.Merchants.Services.IMerchantProductService"/>
    <endpoint address="mexMerchantProductService"
          binding="mexHttpBinding"
          contract="IMetadataExchange" />
  </service>
  <service name="MyCompany.Services.Merchants.MerchantService">
    <endpoint address="" behaviorConfiguration="Proto.Common.EndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Common" contract="MyCompany.Api.Merchants.Services.IMerchantService"/>
    <endpoint address="mexMerchantService"
          binding="mexHttpBinding"
          contract="IMetadataExchange"  />
  </service>
  <service name="MyCompany.Services.Merchants.Workflows.NewMerchantWorkflow">
    <endpoint address="" behaviorConfiguration="Proto.Common.EndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Common" contract="MyCompany.Api.Merchants.Services.INewMerchantServiceWorkflow"/>
    <endpoint address="mexNewMerchantWorkflow"
  binding="mexHttpBinding"
  contract="IMetadataExchange" />
  </service>
  <service name="MyCompany.Services.Merchants.MerchantFreightService">
    <endpoint address="" behaviorConfiguration="Proto.Common.EndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Common" contract="MyCompany.Api.Merchants.Services.IMerchantFreightService"/>
    <endpoint address="mexMerchantFreightService"
  binding="mexHttpBinding"
  contract="IMetadataExchange" />
  </service>
  <service name="MyCompany.Services.Merchants.MerchantAuctionService">
    <endpoint address="" behaviorConfiguration="Proto.Common.EndpointBehavior" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_Common" contract="MyCompany.Api.Pricing.Services.IMerchantAuctionService"/>
    <endpoint address="mexMerchantAuctionService"
  binding="mexHttpBinding"
  contract="IMetadataExchange" />
  </service>
</services>

我已经尝试删除额外的 mex 端点,但这没有任何区别。另外,我检查了合同,对我来说看起来还不错。IMerchantProductService 合约如下:

[ServiceContract(Namespace = "http://www.MyCompany.com/services/", Name = "MerchantProductService")]
[ContractClass(typeof(MerchantProductServiceContracts))]
public interface IMerchantProductService
{
    /// <summary>
    /// Searchs the merchants product catalog using product name, merchant sku or product global id
    /// </summary>
    /// <param name="searchTerm"></param>
    /// <returns></returns>
    [OperationContract]
    List<MerchantProductQuickSearchItem> QuickSearchMerchantProducts(int merchantId, string searchTerm);

    /// <summary>
    /// Gets a merchant product based on the Id
    /// </summary>
    /// <param name="ourMerchantProductId">The id of the product to get</param>
    /// <returns></returns>
    [OperationContract]
    MerchantProduct GetMerchantProduct(int ourMerchantProductId, int merchantId);

    ///etc.

}

IMerchantService 合约如下:

[ServiceContract(Namespace = "http://www.MyCompany.com/services/", Name = "MerchantService")]
[ContractClass(typeof(MerchantServiceContracts))]
public interface IMerchantService
{
    /// <summary>
    /// Gets a merchant instance
    /// </summary>
    /// <param name="merchantId"></param>
    /// <returns></returns>
    [OperationContract]
    Merchant GetMerchant(int merchantId);

    /// <summary>
    /// Gets a merchant's bid settings
    /// </summary>
    /// <param name="merchantId"></param>
    /// <returns></returns>
    [OperationContract]
    MerchantBidSettings GetMerchantBidSettings(int merchantId);

    //etc.
}

到目前为止我尝试过的事情:

  1. 将所有内容更改为 basicHttpBinding。没区别。
  2. 删除了 Protobuf 行为配置。没区别。
  3. 删除各个 mex 端点。没有区别
  4. 尝试了不同的客户端(WCFStorm、WCF 测试客户端)并且都报告了错误的合同
  5. 检查各个 svc 文件是否正在实施预期的合同(它们是)。

我想我的问题是 1)这是否可能(即多个 .svc 文件与 IIS 托管),如果是这样 2)我的配置是否有问题可能导致我的问题。

4

1 回答 1

4

检查每个 .svc 文件的内容。您是否引用了正确的服务实现?您需要 web.config + .svc 文件 + c# 合同定义 + c# 服务实现来获得它。

<%@ ServiceHost 
    Language="C#"
    Debug="true"
    Service="MyCompany.Services.Merchants.MerchantService" %>
于 2013-01-08T18:09:28.907 回答