WCF是否支持自定义绑定+ Websocket + Duplex。 [英] Does WCF Supports custombinding+ Websocket+Duplex.

查看:80
本文介绍了WCF是否支持自定义绑定+ Websocket + Duplex。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个带有Web套接字协议的自定义绑定以及双面绑定的wcf服务。


当我使用双工和自定义绑定创建服务时,托管在控制台上,添加服务参考,我看不到任何url sttarts 使用ws:// localhost:13060。我是否遗漏了配置中的内容。



我在这里发布我的wcf配置。


< system.serviceModel> 
< bindings>
< customBinding>
< binding name =" CustomWsBinding">
< reliableSession acknowledgementInterval =" 00:00:00.2000000" flowControlEnabled = QUOT;真" inactivityTimeout = QUOT; 23:59:59" maxPendingChannels = QUOT; 128" maxRetryCount = QUOT; 8英寸maxTransferWindowSize = QUOT; 128"有序= QUOT;真" />
< compositeDuplex />
< oneWay maxAcceptedChannels =" 128" packetRoutable = QUOT假QUOT;>
< channelPoolSettings idleTimeout =" 00:10:00" leaseTimeout = QUOT; 00:10:00" maxOutboundChannelsPerEndpoint = QUOT; 10" />
< / oneWay>
< textMessageEncoding maxReadPoolSize =" 64" maxWritePoolSize = QUOT; 16" messageVersion = QUOT;默认" writeEncoding = QUOT; UTF-8英寸;>
< readerQuotas maxDepth =" 2147483647" maxStringContentLength = QUOT; 2147483647"的MaxArrayLength = QUOT; 2147483647" maxBytesPerRead = QUOT; 2147483647" maxNameTableCharCount = QUOT; 2147483647" />
< / textMessageEncoding>
< httpTransport manualAddressing =" false" maxBufferPoolSize = QUOT; 2147483647" maxReceivedMessageSize = QUOT; 2147483647" allowCookies = QUOT假QUOT; authenticationScheme = QUOT;匿名" bypassProxyOnLocal = QUOT假QUOT; hostNameComparisonMode = QUOT; StrongWildcard" keepAliveEnabled = QUOT;真" MAXBUFFERSIZE = QUOT; 2147483647" proxyAuthenticationScheme = QUOT;匿名"境界= QUOT;" transferMode = QUOT;缓冲" unsafeConnectionNtlmAuthentication = QUOT假QUOT; useDefaultWebProxy = QUOT;真" />
< / binding>
< / customBinding>
< / bindings>
< services>
< service name =" WCF_WebSocket.TestService" behaviorConfiguration = QUOT; ServiceBehavior">
< endpoint address =""结合= QUOT; customBinding" bindingConfiguration = QUOT; CustomWsBinding"合同= QUOT; WCF_WebSocket.ITestService" />
< host>
< baseAddresses>
< add baseAddress =" http:// localhost:13060 /" />
< / baseAddresses>
< / host>
< endpoint address =" mex"结合= QUOT; mexHttpBinding"合同= QUOT; IMetadataExchange接口" />
< / service>

< / services>
< behavior>
< serviceBehaviors>
< behavior name =" ServiceBehavior">
< serviceDebug includeExceptionDetailInFaults =" false" />
<! - 设置为true以进行调试 - >
< serviceMetadata httpGetEnabled =" true" />
< / behavior>
< / serviceBehaviors>
< / behavior>
将/system.serviceModel>




<预类= "prettyprint"> [的ServiceContract(CallbackContract = typeof运算(ITestServiceCallBack))]
公共接口ITestService
{
[OperationContract]
string GetData(string value);
}

[的ServiceContract]
公共接口ITestServiceCallBack
{
[OperationContract的(IsOneWay =真)]
空隙myCallBack函数(字符串结果) ;
}

 [ServiceBehavior(InstanceContextMode = InstanceContextMode。 PerSession,ConcurrencyMode = ConcurrencyMode.Multiple)] 
公共类TestService:ITestService
{
public ITestServiceCallBack mMCCallback;
private bool isComplete = false;
private string sessionId = string.Empty;

object myLock = new object();
private bool isNewClient = false;

private int myValue;

public TestService()
{
sessionId = Guid.NewGuid()。ToString();
isNewClient = true;
}

公共BOOL用来初始化()
{
尝试
{
mMCCallback = OperationContext.Current.GetCallbackChannel< ITestServiceCallBack>();
if(mMCCallback == null)
{
return false;
}
}
catch(例外e)
{
Console.WriteLine(e);
返回false;
}

返回true;
}

public string GetData(string requestId)
{
Initilize();
Console.WriteLine("客户端与requestId {0}"连接,requestId);
Thread thread = new Thread(CallBackWorker);
thread.Start();
返回$"您已输入:{requestId}且数据为{仅"响应呼叫和会话ID:" + sessionId}" ;;
}

private void CallBackWorker()
{
Thread.Sleep(2000);
for(int i = 0; i< 10; i ++)
{
try
{
Thread.Sleep(500);
string callBacktext ="发送回调:" + i.ToString();
mMCCallback.MyCallBack(callBacktext);
}
catch(exception ex)
{
}

}

isComplete = true;
}

}


解决方案

 

喜Gopi247,

据我所知,如果你想通过扩展自定义绑定使用网络插座,你需要建立websocketsettings这里面的httptransportbindingelement的。

您可以参考以下设置,这与Nethttpbinding相同。

< bindings> 
< customBinding>
< binding name =" CustomWsBinding">
< textMessageEncoding maxReadPoolSize =" 64" maxWritePoolSize = QUOT; 16" messageVersion = QUOT;默认" writeEncoding = QUOT; UTF-8英寸;>
< readerQuotas maxDepth =" 2147483647" maxStringContentLength = QUOT; 2147483647"的MaxArrayLength = QUOT; 2147483647" maxBytesPerRead = QUOT; 2147483647" maxNameTableCharCount = QUOT; 2147483647" />
< / textMessageEncoding>
< httpTransport manualAddressing =" false" maxBufferPoolSize = QUOT; 2147483647" maxReceivedMessageSize = QUOT; 2147483647" allowCookies = QUOT假QUOT; authenticationScheme = QUOT;匿名" bypassProxyOnLocal = QUOT假QUOT; hostNameComparisonMode = QUOT; StrongWildcard" keepAliveEnabled = QUOT;真" MAXBUFFERSIZE = QUOT; 2147483647" proxyAuthenticationScheme = QUOT;匿名"境界= QUOT;" transferMode = QUOT;缓冲" unsafeConnectionNtlmAuthentication = QUOT假QUOT; useDefaultWebProxy = QUOT;真">
< webSocketSettings
disablePayloadMasking =" false"
subProtocol =" Soap"
transportUsage =" Always" />
< / httpTransport>
< / binding>
< / customBinding>
< / bindings>

https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/websocketsettings


不要忘记将绑定配置应用于端点。



如果有任何我可以帮忙的话,请随时告诉我。

最好的问候

亚伯拉罕


I wanted to create a wcf service with custom binding with web socket protocol along with duplex binding.

When i created a service with duplex and custom binding , hosted on console , added service reference, I couldn't see any url sttarts  with ws://localhost:13060. Did i miss something in the configuration.

I am posting my wcf configuration here.

<system.serviceModel>
    <bindings>
      <customBinding>
  <binding name="CustomWsBinding">
    <reliableSession acknowledgementInterval="00:00:00.2000000" flowControlEnabled="true" inactivityTimeout="23:59:59" maxPendingChannels="128" maxRetryCount="8" maxTransferWindowSize="128" ordered="true" />
    <compositeDuplex />
    <oneWay maxAcceptedChannels="128" packetRoutable="false">
      <channelPoolSettings idleTimeout="00:10:00" leaseTimeout="00:10:00" maxOutboundChannelsPerEndpoint="10" />
    </oneWay>
    <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </textMessageEncoding>
    <httpTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true" />
  </binding>
</customBinding> 
    </bindings>
    <services>
      <service name="WCF_WebSocket.TestService" behaviorConfiguration="ServiceBehavior">
        <endpoint address="" binding="customBinding" bindingConfiguration="CustomWsBinding" contract="WCF_WebSocket.ITestService"/>
      <host>
       <baseAddresses>
            <add baseAddress="http://localhost:13060/"/>
       </baseAddresses>
      </host>
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="false" />
          <!-- Set to true for debugging-->
          <serviceMetadata httpGetEnabled="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>


[ServiceContract(CallbackContract = typeof(ITestServiceCallBack))]
    public interface ITestService
    {
        [OperationContract]
        string GetData(string value);
    }

    [ServiceContract]
    public interface ITestServiceCallBack
    {
        [OperationContract(IsOneWay = true)]
        void MyCallBack(string result);
    }

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class TestService : ITestService
    {
        public ITestServiceCallBack mMCCallback;
        private bool isComplete = false;
        private string sessionId = string.Empty;

        object myLock = new object();
        private bool isNewClient = false;

        private int myValue;

        public TestService()
        {
            sessionId = Guid.NewGuid().ToString();
            isNewClient = true;
        }

        public bool Initilize()
        {
            try
            {
                mMCCallback = OperationContext.Current.GetCallbackChannel<ITestServiceCallBack>();
                if (mMCCallback == null)
                {
                    return false;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return false;
            }

            return true;
        }

        public string GetData(string requestId)
        {
            Initilize();
            Console.WriteLine("Client Connected with requestId {0}", requestId);
            Thread thread = new Thread(CallBackWorker);
            thread.Start();
            return $"You entered: {requestId} and  Data is {"only response call and Session Id :" + sessionId}";
        }

        private void CallBackWorker()
        {
            Thread.Sleep(2000);
            for (int i = 0; i < 10; i++)
            {
                try
                {
                    Thread.Sleep(500);
                    string callBacktext = "Sending callback : " + i.ToString();
                    mMCCallback.MyCallBack(callBacktext);
                }
                catch (Exception ex)
                {
                }
                
            }

            isComplete = true;
        }

    }

解决方案

 

Hi Gopi247,
As far as I know, if you want to use web socket by extending the Custom binding, you need to set up the websocketsettings which inside of the httptransportbindingelement.
You could refer to the following settings, which is equivalent with Nethttpbinding.

  <bindings>
      <customBinding>
        <binding name="CustomWsBinding">
          <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" messageVersion="Default" writeEncoding="utf-8">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          </textMessageEncoding>
          <httpTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" allowCookies="false" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true">
            <webSocketSettings 
                       disablePayloadMasking="false"
                       subProtocol="Soap"
                       transportUsage="Always" />
          </httpTransport>
        </binding>
      </customBinding>
</bindings>

https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/wcf/websocketsettings

Don’t forget to apply the binding configuration to endpoint.

Feel free to let me know if there is anything I can help with.
Best Regards
Abraham


这篇关于WCF是否支持自定义绑定+ Websocket + Duplex。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆