1
我已經用netHttpBinding綁定寫了一個wcf服務,並且託管在II8(windows server 2012)中。接口像波紋管。如何從HTML客戶端調用Websocket?
[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 =新的WebSocket(URI); 但我應該在「uri」中調用該服務。我無法獲得.. ???
感謝, Arijit
我已經張貼解答關於類似的話題在這裏: [WCF自託管用JavaScript客戶端的websocket服務] [1] [1]:http://stackoverflow.com/questions/24239953/wcf-self-hosted-websocket-service-with-javascript-client/26527058#26527058 – Amid 2014-10-23 11:32:40