由于某些特定要求,我必须将单个 svc 用于多个服务版本。我已经使用不同的命名空间为每个版本分离了接口契约。我只有一个类(部分)实现所有服务版本。
我的代码如下:
namespace Application.V1
{
[ServiceContract(Namespace = "http://google.com/ApplicationService/v1.0", Name = "IMathService")]
public interface IMathService
}
namespace Application.V2
{
[ServiceContract(Namespace = "http://google.com/ApplicationService/v2.0", Name = "IMathService")]
public interface IMathService
}
应用程序/MathServiceV1.cs 文件:
public partial class MathService : V1.IMathService { }
应用程序/MathServiceV2.cs 文件:
public partial class MathService : V2.IMathService { }
应用程序/MathService.cs 文件:
public partial class MathService {}
我在服务 web.config 中添加了以下内容:
<service behaviorConfiguration="ServiceBehavior" name="Application.MathService">
<endpoint address="V1" binding="wsHttpBinding" contract="Application.V1.IMathService" />
<endpoint address="V2" binding="wsHttpBinding" contract="Application.V2.IMathService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
我有一个MathService.svc
包含以下内容的文件:
<%@ ServiceHost Service="Application.MathService, Application"
Factory="Autofac.Integration.Wcf.AutofacServiceHostFactory, Autofac.Integration.Wcf"%>
如果我使用地址生成代理,http://localhost:8000/MathService.svc
则生成客户端端点,如下所示:
<client>
<endpoint address="http://localhost:8000/MathService.svc/V1"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMathService"
contract="MathService.IMathService" name="WSHttpBinding_IMathService">
</endpoint>
<endpoint address="http://localhost:8000/MathService.svc/V2"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMathService1"
contract="MathService.IMathService1" name="WSHttpBinding_IMathService1">
</endpoint>
</client>
我担心的是客户端端点地址是生成的,MathService.svc/V1
但我想查看V1/MathService.svc
.
如果我使用地址浏览服务,http://localhost:8000/MathService.svc/V1
我会收到HTTP 400 Bad Request
错误消息。
有什么建议么?