我在IIS上有一些WCF服务,一些.net Web应用程序正在使用它 . 我的任务是编写一个新的WCF服务,要求现有的Web应用程序可以使用新服务,而不会更改除了 web.config
之外的任何内容 .
所以我认为我的新服务需要2个接口?我已经完成了,我有三个接口 - ILocationsWCF
(与旧服务中的接口名称相同) ILocationDW
(有新方法)和
ILocationService : ILocationsWCF, ILocationDW.
公共类 LocationService : ILocationService
. 我可以编写一个使用 ILocationService
的新网络应用程序 - 但我无法弄清楚如何使这个新服务有2个 endpoints ,一个用于旧应用程序,一个用于新 endpoints (这样做是因为旧服务是一个有点尴尬,所以我想让它们分开,然后如果机会出现,用新服务重新部署旧应用程序) . 大多数情况下,这种变化是由新的源数据驱动的 - 但我离题了 .
这是我得到的错误:
绑定实例已与侦听URI http:// localhost:10737 / LocationService.svc相关联 . 如果两个 endpoints 想要共享相同的ListenUri,则它们还必须共享相同的绑定对象实例 . 两个冲突的 endpoints 要么在AddServiceEndpoint()调用中,在配置文件中指定,要么在AddServiceEndpoint()和config的组合中指定 .
我对web.config服务模型的尝试:
<system.serviceModel>
<services>
<service name="PPS.Services.Location.LocationService" behaviorConfiguration="LocationServiceBehavior">
<endpoint address=""
binding="basicHttpBinding" name="PPS.Services.Location.LocationService"
bindingNamespace="PPS.Services.Location"
contract="PPS.Services.Location.ILocationService"
bindingConfiguration="BasicHttpBinding_ILocationService"
behaviorConfiguration="HttpBehavior">
</endpoint>
<endpoint address=""
binding="basicHttpBinding" name="PPS.Services.Location.LocationsWCF"
bindingNamespace="PPS.Services.Location"
contract="PPS.Services.Location.ILocationsWCF"
bindingConfiguration="BasicHttpBinding_ILocationsWCF"
behaviorConfiguration="HttpBehavior">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LocationServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="HttpBehavior" />
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ILocationService" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"></binding>
<binding name="BasicHttpBinding_ILocationsWCF" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"></binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
我的界面:
namespace PPS.Services.Location
{
[ServiceContract(Name = "LocationService")]
public interface ILocationService : ILocationsWCF, ILocationServiceDW
{...
namespace PPS.Services.Location
{
[ServiceContract(Name = "LocationsWCF")]
public interface ILocationsWCF
{...
namespace PPS.Services.Location
{
[ServiceContract(Name = "LocationServiceDW")]
public interface ILocationServiceDW
{...
对这些 endpoints 的任何帮助,还是我走错了方向?
编辑 - 新问题!
谢谢你的帮助,marc_s让我超过了那个驼峰 . 现在,我的目标是通过仅更改web.config中的 endpoints 来用新服务替换现有服务 . 我无法让这个工作,我得到的错误如下:
...cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher...
如果我从应用程序中删除旧服务并将其替换为新服务,那么编译并运行它也可以 - 但我不想重新部署所有旧应用程序,我宁愿只更换 endpoints web.config中 . 我甚至可以这样做吗?这两项服务有所不同,主要是一个新的数据库(我们的学生数据现在是一个新的供应商 - 我无法控制),而且我学到了很多,并且能够写出更好的服务 . 我可以在这里做我想做的事情,还是我需要运行2项服务,直到我可以将所有旧应用程序移动到新服务?请注意,当我确定 Contract 等相同时,但如果您需要查看文件,请告诉我哪些文件 . 谢谢 .
1 回答
一个 endpoints =一个 Contract . 如果您将两组服务方法合并到 single 服务 Contract 中(
ILocationService
),则 cannot 有两个单独的 endpoints .你应该做的是有一个服务实现类(
LocationService
),它实现了两个接口:现在,您有一个服务实现,但您可以定义两个单独的 endpoints :
现在你有 two endpoints - 每一个暴露 one service contract - 并提醒你:他们必须拥有 different
address=.....
值!您不能在同一地址上有两个不同的 endpoints