WCF具有多种服务和

时间:2016-10-24 12:24:42

标签: rest wcf service

我正在尝试创建一个在一个程序集中提供多个休息服务的WCF。为了测试它,我创建了两个具有相同内容的服务,这两个服务提供两个接口。

我可以使用网址

获取元数据
  

localhost / testwebservice / services / Service1.svc?wsdl或   本地主机/ testwebservice /服务/ Service2.svc?WSDL

,但是当我尝试执行方法时

  

本地主机/ testwebservice /服务/ Service1.svc /的GetData / 0

,我收到了DestinationUnreachable错误。

web.config文件是

<system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="test.Services.Service1">
        <endpoint address="" binding="webHttpBinding" 
          contract="test.Contracts.IService1" />
        <endpoint address="mex" binding="mexHttpBinding" contract="test.Contracts.IService1" />
      </service>
      <service behaviorConfiguration="ServiceBehavior" name="test.Services.Service2">
        <endpoint address="" binding="webHttpBinding"
          contract="test.Contracts.IService2" />
        <endpoint address="mex" binding="mexHttpBinding" contract="test.Contracts.IService2" />
      </service>
    </services>
    <behaviors>     
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  </system.serviceModel>

每个.cs接口文件都是这样的

namespace test.Contracts
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "GetData/{value}")]
        string GetData(string value);
    }
}

每个.svc文件都是这样的

namespace test.Services
{
    public class Service1 : IService1
    {
        public string GetData(string value)
        {
            return string.Format("You entered: {0}", value);
        }
    }
}

我也希望以 localhost / testwebservice / services / Service1和localhost / testwebservice / services / service2 的形式访问webservice,而不是使用.svc,但是我无法配置webservice为了删除.svc后缀。我试图使用端点的地址,但我无法使其运行。

0 个答案:

没有答案
相关问题