繁体   English   中英

IIS中的多个wcf服务

[英]Multiple wcf services in IIS

我试图在相同的基本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)我的配置有什么问题可能导致我的问题。

检查每个.svc文件的内容。 您是否引用了正确的服务实现? 您需要web.config + .svc文件+ c#contract definition + c#service implementation来获取它。

<%@ ServiceHost 
    Language="C#"
    Debug="true"
    Service="MyCompany.Services.Merchants.MerchantService" %>

暂无
暂无

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

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