WCF 中具有多个合约的多个端点

发布于 2024-10-21 13:43:36 字数 423 浏览 2 评论 0原文

您好,我有 2 个服务合约 IService1 和 IService2

我希望每个服务合约有不同的端点,而且我只想使用 basichttpbinding。

假设 IService1 地址是 http://localhost:4040/MyApp/Service1.svc 那么

我想使用地址 http://localhost:4040/MyApp/Service1.svc/service2 访问 IService2或使用 IService1 地址以外的地址

是否可能?

Hi I have 2 service contracts IService1 and IService2

I want different endpoints for each service contract also I want to use only basichttpbinding.

Suppose IService1 address is http://localhost:4040/MyApp/Service1.svc then

I want to access IService2 with address http://localhost:4040/MyApp/Service1.svc/service2 or with address other than IService1 address

Is it possible ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

儭儭莪哋寶赑 2024-10-28 13:43:36

你在 IIS 中托管这个吗?如果是这样: IIS 规定了您的地址 - 它们被定义为

http://YourServer/YourVirtualDirectory/YourService.svc

因此,如果您想要两个单独的地址,则需要两个单独的虚拟目录...

或者:自主机,那么您有完全的自由地址!

如果您自行托管,您绝对可以定义一个暴露两个端点的服务(在同一实现类中实现两个服务接口):

<services>
   <service name="YourNamespace.ServiceImplementationClass">
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:4040/MyApp/Service1.svc" />
         </baseAddresses>
      </host>
      <endpoint name="Service1"
          address=""
          binding="basicHttpBinding"
          contract="YourNamespace.IService1" />
      <endpoint name="Service2"
          address="Service2"
          binding="basicHttpBinding"
          contract="YourNamespace.IService2" />
   </service>
</services>

因此您的服务 1 可以在定义的基地址(http://localhost: 4040/MyApp/Service1.svc),而您的服务 2 将位于 http://localhost:4040/MyApp/Service1.svc/Service2。这就是你要找的吗?

Are you hosting this in IIS ?? If so: IIS dictates your addresses - they're defined as

http://YourServer/YourVirtualDirectory/YourService.svc

So if you want two separate addresses, you need two separate virtual directories....

Or: self-host, then you have full freedom of addresses!

If you self-host, you could definitely define a service (implementing both service interfaces in the same implementation class) that exposes two endpoints:

<services>
   <service name="YourNamespace.ServiceImplementationClass">
      <host>
         <baseAddresses>
            <add baseAddress="http://localhost:4040/MyApp/Service1.svc" />
         </baseAddresses>
      </host>
      <endpoint name="Service1"
          address=""
          binding="basicHttpBinding"
          contract="YourNamespace.IService1" />
      <endpoint name="Service2"
          address="Service2"
          binding="basicHttpBinding"
          contract="YourNamespace.IService2" />
   </service>
</services>

So your service 1 would be accessible at the base address defined (http://localhost:4040/MyApp/Service1.svc), while your service 2 would be at http://localhost:4040/MyApp/Service1.svc/Service2. Is that what you're looking for??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文