简体   繁体   English

使用net tcp的WCF双工服务:“需要Stream Security ......”

[英]WCF duplex service using net tcp: “Stream Security is required…”

I'm writing a service that allows users to register with it and receive notifications when an event happens. 我正在编写一项服务,允许用户注册并在事件发生时接收通知。 I'm trying to do this with netTcpBinding, but keep coming up with errors, even when running on my local machine. 我正在尝试使用netTcpBinding执行此操作,但即使在本地计算机上运行时也会遇到错误。

When I try to send a notification, I am timing out, getting this error: 当我尝试发送通知时,我超时,收到此错误:

Stream Security is required at http://www.w3.org/2005/08/addressing/anonymous , but no security context was negotiated. http://www.w3.org/2005/08/addressing/anonymous需要Stream Security,但未协商安全上下文。 This is likely caused by the remote endpoint missing a StreamSecurityBindingElement from its binding. 这可能是由远程端点从其绑定中丢失StreamSecurityBindingElement引起的。

For testing I am hosting the service in a console, and it is opening for me and I can see the WSDL and run svcutil on it. 为了测试我在一个控制台中托管服务,它正在为我打开,我可以看到WSDL并在其上运行svcutil。 When I run the client though, and try to send a notification is when the error above shows up. 当我运行客户端时,尝试发送通知是在上面的错误出现时。

Host App.config: 主机App.config:

<system.serviceModel>
<services>
  <service name="CompanyName.WebServices.InterventionService.RegistrationService"
           behaviorConfiguration="RegistrationServiceBehavior">
    <endpoint address="http://localhost:8000/CompanyName/Registration"
              binding="wsDualHttpBinding"
              contract="CompanyName.WebServices.InterventionService.Interfaces.IRegistrationService"/>
    <endpoint address="net.tcp://localhost:8001/CompanyName/Registration"
              binding="netTcpBinding"
              contract="CompanyName.WebServices.InterventionService.Interfaces.IRegistrationService"/>
  </service>
  <service name="CompanyName.WebServices.InterventionService.NotificationService"
           behaviorConfiguration="NotificationServiceBehavior">
    <endpoint address="http://localhost:8010/CompanyName/Notification"
              binding="wsDualHttpBinding"
              contract="CompanyName.WebServices.InterventionService.Interfaces.INotificationService"/>
    <endpoint address="net.tcp://localhost:8011/CompanyName/Notification"
              binding="netTcpBinding"
              contract="CompanyName.WebServices.InterventionService.Interfaces.INotificationService"/>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="RegistrationServiceBehavior">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="http://localhost:8000/CompanyName/Registration"/>
    </behavior>
    <behavior name="NotificationServiceBehavior">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="http://localhost:8010/CompanyName/Notification"/>
    </behavior>
    <behavior name="netTcpRegistrationServiceBehavior">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="net.tcp://localhost:8001/CompanyName/Registration"/>
    </behavior>
    <behavior name="netTcpNotificationServiceBehavior">
      <serviceMetadata httpGetEnabled="true"
                       httpGetUrl="net.tcp://localhost:8011/CompanyName/Notification"/>
    </behavior>
  </serviceBehaviors>
</behaviors>

Here is the client App.config: 这是客户端App.config:

<system.serviceModel>
<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IRegistrationService">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport clientCredentialType="None"/>
      </security>
    </binding>
    <binding name="NetTcpBinding_INotificationService">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </netTcpBinding>
  <wsDualHttpBinding>
    <binding name="WSDualHttpBinding_IRegistrationService">
      <reliableSession ordered="true"/>
      <security mode="None">
        <message clientCredentialType="None" negotiateServiceCredential="false"/>
      </security>
    </binding>
    <binding name="WSDualHttpBinding_INotificationService">
      <reliableSession ordered="true"/>
      <security mode="None">
        <message clientCredentialType="None" negotiateServiceCredential="false"/>
      </security>
    </binding>
  </wsDualHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:8000/GPS/Registration"
            binding="wsDualHttpBinding"
            bindingConfiguration="WSDualHttpBinding_IRegistrationService"
            contract="IRegistrationService"
            name="WSDualHttpBinding_IRegistrationService">
  </endpoint>
  <endpoint address="net.tcp://localhost:8001/GPS/Registration"
            binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_IRegistrationService"
            contract="IRegistrationService"
            name="NetTcpBinding_IRegistrationService">
  </endpoint>
  <endpoint address="http://localhost:8010/GPS/Notification"
            binding="wsDualHttpBinding"
            bindingConfiguration="WSDualHttpBinding_INotificationService"
            contract="INotificationService"
            name="WSDualHttpBinding_INotificationService">
  </endpoint>
  <endpoint address="net.tcp://localhost:8011/GPS/Notification"
            binding="netTcpBinding"
            bindingConfiguration="NetTcpBinding_INotificationService"
            contract="INotificationService"
            name="NetTcpBinding_INotificationService">
  </endpoint>
</client>

I've omitted a lot of the registration code since I am only trying to get the notification working right now. 我省略了很多注册码,因为我现在只是想让通知正常工作。

The plan is to host this in a windows service in 2003 Server that is not part of the customer's domain (their setup), and the client computers will be on the customer's domain. 计划是在2003 Server中的Windows服务中托管它,该服务不属于客户的域(他们的设置),客户端计算机将位于客户的域中。

Edit: 编辑:

I have added the bindings to the host's App.config: 我已将绑定添加到主机的App.config:

<bindings>
  <netTcpBinding>
    <binding name="NetTcpBinding_IRegistrationService">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport clientCredentialType="None"/>
      </security>
    </binding>
    <binding name="NetTcpBinding_INotificationService">
      <security mode="None">
        <message clientCredentialType="None"/>
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </netTcpBinding>
  <wsDualHttpBinding>
    <binding name="WSDualHttpBinding_IRegistrationService">
      <reliableSession ordered="true"/>
      <security mode="None">
        <message clientCredentialType="None" negotiateServiceCredential="false"/>
      </security>
    </binding>
    <binding name="WSDualHttpBinding_INotificationService">
      <reliableSession ordered="true"/>
      <security mode="None">
        <message clientCredentialType="None" negotiateServiceCredential="false"/>
      </security>
    </binding>
  </wsDualHttpBinding>
</bindings>

This still errors, with the same Steam Security is required error message. 这仍然是错误,具有相同的Steam Security是必需的错误消息。 Trying a small subset of this app in a new solution. 在新解决方案中尝试此应用的一小部分。

Well, your problem appears to be this: 好吧,你的问题似乎是这样的:

  • on the server side, you use a default netTCP binding with no parameters - you don't change anything on it. 在服务器端,您使用没有参数的默认netTCP绑定 - 您不会更改任何内容。 netTCP defaults to transport-level security with Windows credentials netTCP默认使用Windows凭据进行传输级安全性

  • on your client however, you explicitly turn OFF any security on the netTCP binding 但是,在您的客户端上,您明确关闭了netTCP绑定的任何安全性

So the two don't match and don't agree on what to do. 所以两者不匹配,不同意做什么。

Either you need to turn OFF all security on BOTH ends - server AND client - or you need to just use the secure defaults (with Windows credentials). 您需要关闭BOTH两端的所有安全性 - 服务器和客户端 - 或者您只需使用安全默认值(使用Windows凭据)。

Marc

I think it turns out this is one of those horrible error messages that leads you into many different directions. 我认为事实证明这是导致你进入许多不同方向的那些可怕的错误信息之一。 The above answers is correct for that case. 上述答案对于这种情况是正确的。 My case was different - my security settings were identical on client and serve. 我的情况不同 - 我的安全设置在客户端和服务上是相同的。

In my case, this link pointed out my particular flaw: http://www.netframeworkdevs.com/windows-communication-foundation-wcf/error-invoking-service-with-a-net-tcp-binding-123918.shtml . 就我而言,这个链接指出了我的特殊缺陷: http//www.netframeworkdevs.com/windows-communication-foundation-wcf/error-invoking-service-with-a-net-tcp-binding-123918.shtml

My service-side app.config for the Endpoint had bindingName as the attribute to name the binding configuration ... instead of bindingConfiguration . 我的端点的服务端app.config使用bindingName作为命名绑定配置的属性...而不是bindingConfiguration I don't think there even is an attribute named bindingName on an endpoint . 我认为在endpoint上甚至没有名为bindingName的属性。

So ... my take away is that this error means "there is a WCF configuration error" perhaps narrowed to the service-side configuration. 所以......我的看法是,这个错误意味着“有一个WCF配置错误”可能缩小到服务端配置。 Ugh. 啊。

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

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