我有一种方式WCF服务我想在服务端跟踪哪个客户端称为我的服务

时间:2012-06-21 10:20:05

标签: c# .net wcf

我有一种方式WCF服务我想跟踪哪个客户端称为我的服务

//HOST
private void ButtonStart_Click(object sender, EventArgs e)
{
    try
    {
        if (m_objPinDataServiceHost == null)
        {
            m_sMachineName = ConfigurationManager.AppSettings["MACHINENAME"];
            m_sPortNumber = ConfigurationManager.AppSettings["PORTNUMBER"];
            m_objSTB = new ServiceThrottlingBehavior();
            m_objSTB.MaxConcurrentCalls = 400;
            m_objSTB.MaxConcurrentInstances = 400;
            m_objSTB.MaxConcurrentSessions = 400;

            m_objDataServiceHost = new ServiceHost(typeof(DataService));
            sAddress = String.Format("net.tcp://{0}:{1}/DataService", m_sMachineName, m_sPortNumber);
            m_objDataServiceHost.AddServiceEndpoint(typeof(IDataContract), GetTcpBinding(), sAddress);
            m_objDataServiceHost.Description.Behaviors.Add(m_objSTB);
            m_objDataServiceHost.Open();
            m_objDataServiceHost.Faulted += new EventHandler(m_objPlylstInstHost_Faulted);
            labelControl1.Text = "Connected";
            labelControl1.ForeColor = Color.Green;

        }
    }
    catch (Exception)
    {


    }

}


private NetTcpBinding GetTcpBinding()

{
    XmlDictionaryReaderQuotas objReaderQuota = new XmlDictionaryReaderQuotas
    {
        MaxStringContentLength = Convert.ToInt32(ConfigurationManager.AppSettings["MAXSTRINGCONTENTLENGTH"]),
        MaxArrayLength = Convert.ToInt32(ConfigurationManager.AppSettings["MAXARRAYLENGTH"])
    };

    m_objbinding = new NetTcpBinding();
    m_objbinding.MaxReceivedMessageSize = Convert.ToInt64(ConfigurationManager.AppSettings["MAXRECEIVEDMESSAGESIZE"]);
    m_objbinding.MaxBufferPoolSize = Convert.ToInt64(ConfigurationManager.AppSettings["MAXBUFFERPOOLSIZE"]);
    m_objbinding.ReaderQuotas = objReaderQuota;
    m_objbinding.Security.Mode = SecurityMode.None;
    m_objbinding.ReceiveTimeout = new TimeSpan(0, 0, 59);

    return m_objbinding;
}

//End HOST

0 个答案:

没有答案