简体   繁体   English

如何从HTML客户端调用Websocket?

[英]How to Call Websocket from HTML Client?

I have written one wcf Service with netHttpBinding binding and hosted in II8(windows server 2012).The interfaces are like the bellow. 我写了一个带有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);
}

now I have the service class implementation like the bellow.. 现在,我有了像下面这样的服务类实现。

 [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;
    }
}

and the web config like the bellow.. 以及像下面这样的网络配置。

<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>

Now How Can I call the Service from the HTML5 client.?? 现在,如何从HTML5客户端调用服务。?

My Service URL is a link 我的服务网址是一个链接

I am trying to write the client var websocket = new WebSocket(uri); 我正在尝试编写客户端var websocket = new WebSocket(uri); but what should I put in the "uri" to call the service.I am not able to get..??? 但是我应该在“ uri”中键入什么来调用该服务。我无法获得.. ???

Thanks, Arijit 谢谢,Arijit

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

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