Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从HTML客户端调用Websocket?_Javascript_Html_Wcf_Websocket - Fatal编程技术网

Javascript 如何从HTML客户端调用Websocket?

Javascript 如何从HTML客户端调用Websocket?,javascript,html,wcf,websocket,Javascript,Html,Wcf,Websocket,我已经编写了一个带有netHttpBinding绑定的wcf服务,并托管在II8(windows server 2012)中 [ServiceContract(CallbackContract = typeof(IDuplexCallbackContract))] public interface IHelloWebSocket { [OperationContract(IsOneWay = true, Action = "*")] void SayHelloDuplexRecei

我已经编写了一个带有netHttpBinding绑定的wcf服务,并托管在II8(windows server 2012)中

[ServiceContract(CallbackContract = typeof(IDuplexCallbackContract))]
public interface IHelloWebSocket
{
   [OperationContract(IsOneWay = true, Action = "*")] 
   void SayHelloDuplexReceive(string name);
}

[ServiceContract]
public interface IDuplexCallbackContract
{
    [OperationContract(IsOneWay = true, Action = "*")] 
    void SayingHelloSend(string message);
}
现在我有了如下所示的服务类实现

 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class HelloWebSocket : IHelloWebSocket
{
    /// <summary>
    /// Call back instance called from service to client.
    /// </summary>
    IDuplexCallbackContract _callback = null;

    public HelloWebSocket()
    {
        _callback =
            OperationContext.Current.GetCallbackChannel<IDuplexCallbackContract>();
    }

    public void SayHelloDuplexReceive(string name)
    {
        _callback.SayingHelloSend("Hello " + name + " by WebSockets");

        //return "Hello " + name;
    }
}
<system.serviceModel>
     <services>
       <service name="WebSocketUndersranding.HelloWebSocket">
          <endpoint address=""
            binding="netHttpBinding"
            contract="WebSocketUndersranding.IHelloWebSocket"/>
     </service>
    </services>
     <behaviors>
          <serviceBehaviors>
              <behavior name="">
                  <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                 <serviceDebug includeExceptionDetailInFaults="false" />
             </behavior>
         </serviceBehaviors>
     </behaviors>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
           multipleSiteBindingsEnabled="true" />
   </system.serviceModel>
[ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)]
公共类HelloWebSocket:IHelloWebSocket
{
/// 
///从服务调用回叫实例到客户端。
/// 
IDuplexCallbackContract _callback=null;
公共HelloWebSocket()
{
_回拨=
OperationContext.Current.GetCallbackChannel();
}
public void SayHelloDuplexReceive(字符串名称)
{
_callback.SayingHelloSend(“Hello”+name+”由WebSockets提供);
//返回“Hello”+name;
}
}
还有下面的web配置

 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant)]
public class HelloWebSocket : IHelloWebSocket
{
    /// <summary>
    /// Call back instance called from service to client.
    /// </summary>
    IDuplexCallbackContract _callback = null;

    public HelloWebSocket()
    {
        _callback =
            OperationContext.Current.GetCallbackChannel<IDuplexCallbackContract>();
    }

    public void SayHelloDuplexReceive(string name)
    {
        _callback.SayingHelloSend("Hello " + name + " by WebSockets");

        //return "Hello " + name;
    }
}
<system.serviceModel>
     <services>
       <service name="WebSocketUndersranding.HelloWebSocket">
          <endpoint address=""
            binding="netHttpBinding"
            contract="WebSocketUndersranding.IHelloWebSocket"/>
     </service>
    </services>
     <behaviors>
          <serviceBehaviors>
              <behavior name="">
                  <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
                 <serviceDebug includeExceptionDetailInFaults="false" />
             </behavior>
         </serviceBehaviors>
     </behaviors>
      <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
           multipleSiteBindingsEnabled="true" />
   </system.serviceModel>

现在我如何从HTML5客户端调用该服务

我的服务URL是一个链接

我正试着给客户写信 var websocket=新的websocket(uri); 但是我应该在“uri”中输入什么来调用该服务。我无法获取

谢谢,
Arijit

您可以使用本文作为示例,从以下内容开始:


我在这里发布了一个关于类似主题的答案:[wcf带javascript客户端的自托管websocket服务][1][1]: