在NodeJs中使用WCF服务(WsHttp Binding)

时间:2016-03-09 12:04:49

标签: c# node.js web-services wcf

我正在尝试使用NodeJS来使用WCF服务。我使用BasicHttpBinding尝试了security mode="TransportWithMessageCredential"。它工作正常。 但是,如果我尝试使用WsHttpBindingsecurity mode="TransportWithMessageCredential"来使用该服务,则会引发以下错误:

  

“无法处理邮件。这很可能是因为   操作'sjmisc'不正确或因为   消息包含无效或过期的安全上下文令牌或   因为绑定之间存在不匹配。安全上下文   如果服务中止了该通道,则令牌将无效   闲置。防止服务中止空闲会话   过早增加服务端点上的接收超时   结合“。

http://tempuri.org/IService1/GetData

这是我的网络配置

<bindings>
  <wsHttpBinding>
    <binding name="WsHttpBinding" maxReceivedMessageSize="104857600" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:01:00" sendTimeout="00:01:00" messageEncoding="Text" textEncoding="utf-8">
      <!--Maximum size of the message which can be processed by the binding is 100 MB-->
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None"/>
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<services>
  <service name="WcfService1.Service1" behaviorConfiguration="DefaultServiceBehaviors">
    <endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1" name="WsHttpEndpoint" bindingConfiguration="WsHttpBinding"/>
  </service>
</services>

这是我的NodeJS文件

var WSHttpBinding = require('wcf.js').WSHttpBinding
  , Proxy = require('wcf.js').Proxy
  , binding = new WSHttpBinding(
    { 
      SecurityMode: "TransportWithMessageCredential"
    , TransportClientCredentialType:"None"
    , MessageClientCredentialType: "UserName"
    })
  , proxy = new Proxy(binding, "https://localhost:44301/Service1.svc")
  , message = '<Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">'+
      '<Body>'+
        '<GetData xmlns="http://tempuri.org/">'+
            '<value>12345</value>'+
        '</GetData>'+
      '</Body>'+
   '</Envelope>'

   proxy.ClientCredentials.Username.Username = "xyz"
   proxy.ClientCredentials.Username.Password = "xyz"
   proxy.send(message, "http://tempuri.org/IService1/GetData",

  function(response, ctx) {
      console.log(response)
  });

0 个答案:

没有答案