【发布时间】:2012-09-29 06:43:24
【问题描述】:
由于某些特定要求,我必须为多个服务版本使用单个 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
}
Application/MathServiceV1.cs 文件:
public partial class MathService : V1.IMathService { }
Application/MathServiceV2.cs 文件:
public partial class MathService : V2.IMathService { }
Application/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 错误。
有什么建议吗?
【问题讨论】:
-
请解释一下“让任何客户都可以浏览服务”是什么意思?
-
我的意思是如果地址格式是localhost:8000/V1/MathService.svc而不是localhost:8000/MathService.svc/V1,最终用户可以浏览服务。
标签: wcf dependency-injection versioning autofac