gpt4 book ai didi

javascript - 如何从 HTML 客户端调用 Websocket?

转载 作者:行者123 更新时间:2023-11-30 18:03:40 25 4
gpt4 key购买 nike

我写了一个 wcf 服务,绑定(bind)了 netHttpBinding 并托管在 II8(windows server 2012)中。接口(interface)如下所示。

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

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

我的服务 URL 是一个链接

我正在尝试编写客户端 var websocket = new WebSocket(uri);但是我应该在“uri”中输入什么来调用服务。我无法获得..???

谢谢,阿里 git

最佳答案

关于javascript - 如何从 HTML 客户端调用 Websocket?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16302108/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com