我可以在WCF服务中使用wsHttpBinding和webHttpBinding吗?

问题描述:

我有一个自定义的用户名 - 密码WCF服务,需要由Windows客户端(Winforms应用程序)以及Web客户端(html / aspx页面)调用。我在web.config中有两个端点声明,但为了使其工作,我必须对其中一个进行注释,因此,只有与该未注释端点关联的客户端类型才能访问该服务。如果我取消评论,并评论另一个,其他客户端可以访问它。我不能保留它们,所以我无法从两种类型的客户端访问它。

I have a custom username-password WCF service that needs to be called by Windows client (Winforms application) as well as by Web client (html/aspx page). I have two endpoints declarations in web.config but, to make it work, I have to comment one of them and so, only the client type, associated with that un-commented endpoint, can access the service. If I un-comment that, and comment the other one, other client can access it. I can''t keep both of them and so I can''t access it from both types of clients.

<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
    <endpoint address="" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"

     contract="BeST.Service.IService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost/" />
      </baseAddresses>
    </host>
  </service>



正如代码所示,我需要使用两个端点(在两个端点之上),如果我想让这个服务对两个客户端都有效,或者如果还有另一种方法可以完成它,请帮忙!


just as the code shows, I need to use both endpoints (above two endpoints) if I want to make this service work for both clients OR, if there''s another way to have it done, please help!

更改其中一个端点的地址属性并在服务URL中使用它,它应该工作;您的案例中出现的问题是两个端点的地址的相似性。

change the address property of one of the endpoints and use that in your service URL, it should work; the problem occurring in your case is the similarity of "address" of two endpoints.
<service behaviorconfiguration="Behavior1" name="BeST.Service.Service">
  <endpoint>address="web" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
  <endpoint address="" binding="wsHttpBinding" bindingconfiguration="Binding1">
    contract="BeST.Service.IService" />
  <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  <host>
    <baseaddresses>
      <add baseaddress="http://localhost/" />
    </baseaddresses>
  </host>
</endpoint></service>