我想在同一個基礎URL(因此我的項目有多個.svc文件)在IIS下運行多個WCF服務。當我有一項服務時,一切正常,但當我添加其他服務時會出現問題。當我嘗試訪問這些附加服務時,客戶似乎認爲合同是「IMerchantService」合同。例如,如果我瀏覽到http://merchants.localtest.me/MerchantProductService.svc?wsdl(本地託管服務的地址),則返回的服務定義是IMerchantService而不是IMerchantProductService。此外,當我瀏覽到http://merchants.localtest.me/MerchantProductService.svc時,標題是「MerchantService」,而不是我所期望的「MerchantProductService」。IIS中的多個wcf服務
我的服務配置如下:
<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.
}
事情我至今嘗試過:
- 改變一切,以basicHttpBinding的。沒有區別。
- 刪除了Protobuf行爲配置。沒有區別。
- 刪除單個mex端點。沒有什麼區別
- 嘗試了不同的客戶端(WCFStorm,WCF測試客戶端)和所有合同報告錯誤
- 檢查發現個別SVC文件正在實施的預期合同(他們是)。
我想我的問題是1)這甚至可能(即與IIS託管多個.svc文件),如果是的話2)是否有我的配置可能會導致我的問題有問題。
我認爲你只需要一個節點和多個節點。你應該可以做到這一點。 –
lcryder
嗨...謝謝,但這不適用於我的實例,因爲我有多個服務,每個都有自己的合同。解決方案如下。 –