7

首先,我会道歉,因为这可能是重复的,但我读到的所有内容似乎都不完整或令人困惑,因为我对 WCF 很陌生。

我基本上希望在 IIS 中部署一个 WCF 服务,可以访问 2 个端点,并且整天都在绕圈子:(

我有一个具有以下结构的服务库 WCF dll

App.config
TestSvc1.cs
ITestSvc1.cs
TestSvc2.cs
ITestSvc2.cs

这在 VS WCF 测试客户端中运行良好,现在我正在部署到 IIS,所以我创建了一个 WCF 服务应用程序并引用了 dll。该项目具有以下结构

Service1.svc
Web.config

Service1.svc包含这个

<%@ ServiceHost Language="C#" Debug="true" 
    Service="WCFServices.TestServices.ITestSvc1" CodeBehind="Service1.svc.cs" %>

web.config的有以下

<services>
   <service name="WCFServices.TestServices.TestSvc2">
      <endpoint 
          address="" 
          binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" 
          contract="WCFServices.TestServices.ITestSvc2">
          <identity>
            <dns value="localhost" />
          </identity>
      </endpoint>
      <endpoint 
           address="mex" 
           binding="mexHttpBinding"  
           contract="IMetadataExchange" />
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc2/" />
         </baseAddresses>
      </host>
   </service>
   <service name="WCFServices.TestServices.TestSvc1">
      <endpoint 
          address="" 
          binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" 
          contract="WCFServices.TestServices.ITestSvc1"  
          listenUri="http://localhost:8080/wcf2/service1.svc">
          <identity>
            <dns value="" />
          </identity>
      </endpoint>
      <endpoint 
          address="" 
          binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" 
          contract="WCFServices.TestServices.ITestSvc2" 
          listenUri="http://localhost:8080/wcf2/service1.svc">
          <identity>
            <dns value="" />
          </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange" />
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:8080/wcf2/TestServices/TestSvc1/" />
         </baseAddresses>
      </host>
   </service>     
</services>

任何帮助将不胜感激。如您所见,我尝试web.configService1.svc

我还阅读了有关创建继承这些接口的类的信息,但我不确定如何根据上面的内容来实现它。我需要修改Service1.svc吗?

public interface MultipleSvc : ITestSvc1, ITestSvc2
{
   // What exactly do I put here? I have no idea, do I leave it blank? This didn't work for me
}

任何帮助将不胜感激,谢谢:)

4

2 回答 2

11

黄金法则:.svc= 一项服务(或更具体地说:一个服务实现类)

因此,如果您确实有两个独立的、不同的服务(在 classesWCFServices.TestServices.TestSvc1和中WCFServices.TestServices.TestSvc2),那么您需要两个.svc文件(每个文件一个,用于每个服务)

可以做的是拥有一个服务实现类来实现两种服务合同:

public class MultipleServices : ITestSvc1, ITestSvc2
{
   // implement the service logic here, for both contracts
}

在这种情况下,一个 svc 文件就足够了(该.svc文件是每个实现类的,并且可以托管多个服务合同)。但是您也需要更改配置 - 因为您实际上只有一个服务类(因此:一个<service>标签)和其中托管的多个合同:

<services>
   <service name="WCFServices.TestServices.MultipleServices">
      <endpoint 
          address="Service1" 
          binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" 
          contract="WCFServices.TestServices.ITestSvc1">
          <identity>
            <dns value="" />
          </identity>
      </endpoint>
      <endpoint 
          address="Service2" 
          binding="wsHttpBinding" bindingConfiguration="LargeSizeMessages" 
          contract="WCFServices.TestServices.ITestSvc2">
          <identity>
            <dns value="localhost" />
          </identity>
      </endpoint>
      <endpoint 
           address="mex" 
           binding="mexHttpBinding"  
           contract="IMetadataExchange" />
   </service>     
</services>

另外:由于您似乎在 IIS 中托管 WCF 服务,因此定义任何<baseAddress>值都没有意义 - 服务的“基”地址是文件所在的位置 (URI) *.svc

于 2013-01-15T11:48:47.333 回答
0

您不需要两个 svc 文件。选择 ServiceReference1.Service1Client 或 ServiceReference1.Service2Client。

于 2016-11-08T08:22:33.120 回答