简体   繁体   English

WCF wsHttpBinding和BasicHttpBinding在同一个WCF服务应用程序中

[英]WCF wsHttpBinding and BasicHttpBinding in same WCF Service Application

I have been told that wsHttpBinding does not support older clients that still need to use older version of SOAP. 我被告知wsHttpBinding不支持仍需要使用旧版SOAP的旧客户端。 I want to add a BasicHttpBinding endpoint in the same WCF Service Application so that clients can use either endpoint depending on their technology they are running. 我想在同一个WCF服务应用程序中添加一个BasicHttpBinding端点,以便客户端可以使用任一端点,具体取决于它们正在运行的技术。 I am confused as to what the address to use for each of them. 我对每个人使用的地址感到困惑。 The default wsHttpBinding has no address set. 默认的wsHttpBinding没有设置地址。 What should the address be for BasicHttpBinding endpoint? BasicHttpBinding端点的地址应该是什么? Shouldn't the address for the wsHttpBinding be (for my example) http://localhost/WcfService1/Service1.svc ? 不应该是wsHttpBinding的地址(对于我的例子) http://localhost/WcfService1/Service1.svc

There's two things you need to consider here: 这里有两件事你需要考虑:

  • if your hosting in IIS (or WAS as part of IIS7), you cannot set a base address - the base address for your service will be the virtual directory where the MyService.svc file lives. 如果您在IIS(或WAS作为IIS7的一部分)中托管,则无法设置基址 - 您的服务的基址将是MyService.svc文件所在的虚拟目录。 You can still set relative addresses, though 但是,您仍然可以设置相对地址

  • if you self-host, you typically will add base addresses in your config, so you can spare yourself having to spell out the entire address all the time (but you can - if you wish to do so). 如果你是自托管的,你通常会在你的配置中添加基地址,这样你就可以不必一直拼出整个地址(但你可以 - 如果你愿意的话)。

So if you have your MyService.svc inside a virtual directory called MyApp on your localhost machine, and then use this config: 因此,如果您的MyService.svc位于localhost机器上名为MyApp的虚拟目录中,然后使用此配置:

<service name="MyService" behaviorConfiguration="Default">
    <endpoint 
        address="wsHttp"  
        binding="wsHttpBinding" 
        contract="IMyService" />
  <endpoint 
        address="basic" 
        binding="basicHttpBinding" 
        contract="IMyService" />
</service>

then your "old-style" basicHttp service will be reachable at: 那么你的“旧式”basicHttp服务将在以下地址到达:

http://localhost/MyApp/MyService.svc/basic

and your new wsHttp driven service will be reachable at: 并且您的新wsHttp驱动服务将在以下位置访问:

http://localhost/MyApp/MyService.svc/wsHttp

You can name those relative addresses (anything after .../MyApp/MyService.svc ) anything you like - just make sure they're different from one another. 您可以将这些相对地址(任何在.../MyApp/MyService.svc之后的任何内容)命名为您喜欢的名称 - 只需确保它们彼此不同即可。

Hosting in IIS --> location (virtual directory) of your *.svc file becomes your base address. 在IIS中托管 - > .svc文件的位置(虚拟目录)将成为您的基本地址。

If you self-host your service inside a console app or a Windows NT Service, you get to set your base addresses yourself: 如果您在控制台应用程序或Windows NT服务中自行托管您的服务,您可以自己设置基本地址:

<services>
  <service name="MyService" behaviorConfiguration="Default">
    <host>
      <baseAddresses>
         <add baseAddress="http://localhost:8185/Services/" />
      </baseAddresses>
    </host>
  </service>
</services>

Now in this case, your "old-style" basicHttp service will be reachable at: 现在在这种情况下,您的“旧式”basicHttp服务将在以下位置访问:

http://localhost:8185/Services/basic

and your new wsHttp driven service will be reachable at: 并且您的新wsHttp驱动服务将在以下位置访问:

http://localhost:8185/Services/wsHttp

You can define a base address for each of the transports, eg one for http://, one for net.tcp:// and so on. 您可以为每个传输定义基址,例如,一个用于http://,一个用于net.tcp://,依此类推。

And of course, if you really must, you can also define your complete addresses inside your <endpoint> element for each of the service endpoints - this gives you total flexibility (but only works in self-hosting scenarios). 当然,如果您真的必须,您还可以在每个服务端点的<endpoint>元素内定义完整的地址 - 这为您提供了全面的灵活性(但仅适用于自托管方案)。

Marc

In WCF you have a base address and an enpoint address, in your case you can do something like this: 在WCF中,您有一个基地址和一个enpoint地址,在您的情况下,您可以执行以下操作:

<service name="WcfEndpoints.Service1" behaviorConfiguration="WcfEndpoints.Service1Behavior">
  <!-- Service Endpoints -->
  <endpoint address="new" binding="wsHttpBinding" contract="WcfEndpoints.IService1" />
  <endpoint address="old" binding="basicHttpBinding" contract="WcfEndpoints.IService1" />
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>

Note you will need additional work for the basicHttpBinding endpoint to work with older (asmx) clients 请注意,basicHttpBinding端点需要额外的工作才能使用旧的(asmx)客户端

http://msdn.microsoft.com/en-us/library/ms751433.aspx http://msdn.microsoft.com/en-us/library/ms751433.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM