在单独的应用程序中使用相同的根baseaddress

时间:2015-02-16 21:48:39

标签: c# web-services wcf

我正在尝试创建两个独立的端点,这两个端点托管在两个单独的Windows服务中。 http:// mydevice / thisresource

http:// mydevice / thatresource

第一项服务的app.config文件如下所示:

<service behaviorConfiguration="WebHttpServiceBehavior" name="MyService1">
  <endpoint address="" behaviorConfiguration="WebEndpointBehavior"
      binding="webHttpBinding" bindingConfiguration="StreamingWebHttpBinding"
      name="WebEndpoint" contract=MyContract" />
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost" />
    </baseAddresses>
  </host>
</service>

在第一个服务的合同中,我的方法属性如下所示:

[OperationContract]
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/this")]
bool PutThisResource(int i);

我的第二项服务的app.config文件如下所示:

<service behaviorConfiguration="WebHttpServiceBehavior" name="MyService2">
  <endpoint address="" behaviorConfiguration="WebEndpointBehavior"
      binding="webHttpBinding" bindingConfiguration="StreamingWebHttpBinding"
      name="WebEndpoint" contract=MyContract2" />
  <host>
    <baseAddresses>
      <add baseAddress="http://localhost" />
    </baseAddresses>
  </host>
</service>

在第二个服务的合同中,我的方法属性如下所示:

[OperationContract]
[WebInvoke(Method = "PUT", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/that")]
bool PutThatResource(int i);

此代码将在外部世界将会遇到的独立Windows设备上运行。我并不是真的想要使用像http://localhost/myservice1http://localhost/myservice2这样的URI命名约定,因为就像我说的那样,我希望所有内容对用户来说都是无缝的。由于除此外部接口之外的其他原因,后面的代码被分解为单独的Windows服务。这一切都在Windows Embedded上运行,其愿景是设备更像是一个设备,客户端甚至无法洞察内部运行的操作系统。

当我尝试运行这两个服务时,我得到一个AddressAlreadyInUseException。我从2009年的这篇文章中假设

Can several WCF services share a common BaseAddress?

我无法使用相同的根地址。有一种简单的方法可以在单独的Windows服务(AppDomains)之间共享根目录吗?

我在xml配置中不使用baseAddress并为每个路径创建单独的WCF服务取得了一些成功,但这需要做很多工作。

0 个答案:

没有答案