Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class
Windows Communication Foundation in one Class Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Go Back  Xtreme Visual Basic Talk > > > Windows Communication Foundation in one Class


Reply
 
Thread Tools Display Modes
  #1  
Old 01-29-2014, 10:00 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default Windows Communication Foundation in one Class


Hello dear reader,

I have the following problem, i have both the client and the server in one need project, which almost works.... The server is running and responding but at the same time giving me time outs... can some one take a look at what i am doing wrong? I choose not use App.config file to configure the client nor the server, its all done in code.

The server code :

Code:
<ServiceContract(SessionMode:=SessionMode.Required, CallbackContract:=GetType(Core.IServiceCallBack))>
Public Interface IService
    <OperationContract> Sub Join(Name As String)
    <OperationContract(isoneway:=True)> Sub ChangeBackColor(NewColor As System.Drawing.Color)
    <OperationContract(isoneway:=True)> Sub ChangeServerPath(NewPath As String)
End Interface
Public Interface IServiceCallBack
    <OperationContract> Sub NotifyMemberJoined(Name As String)
    <OperationContract(isoneway:=True)> Sub NotifyBackcolorChanged(Color As System.Drawing.Color)
    <OperationContract(isoneway:=True)> Sub NotifyServerPathChanged(NewPath As String)
End Interface
<ServiceBehavior(ConcurrencyMode:=ConcurrencyMode.Reentrant, InstanceContextMode:=InstanceContextMode.PerCall, UseSynchronizationContext:=False)>
Public Class Service
    Implements Core.IService

    Private m_MemberList As New List(Of Core.IServiceCallBack)

    Public Sub Join(Name As String) Implements IService.Join
        Dim Guest As Core.IServiceCallBack = OperationContext.Current.GetCallbackChannel(Of Core.IServiceCallBack)()
        If Not m_MemberList.Contains(Guest) Then
            m_MemberList.Add(Guest)
        End If
        For Each Member As IServiceCallBack In m_MemberList
            Member.NotifyMemberJoined(Name)
        Next
    End Sub
    Public Sub ChangeBackColor(NewColor As Drawing.Color) Implements Core.IService.ChangeBackColor
        For Each Member As IServiceCallBack In m_MemberList
            Member.NotifyBackcolorChanged(NewColor)
        Next
    End Sub
    Public Sub ChangeServerPath(NewPath As String) Implements Core.IService.ChangeServerPath
        For Each Member As IServiceCallBack In m_MemberList
            Member.NotifyServerPathChanged(NewPath)
        Next
    End Sub
End Class

Public Class Host
    Private Shared Host As System.ServiceModel.ServiceHost

    Public Shared Function Open() As Boolean
        Try
            Dim HttpBaseAddress As Uri = New Uri("http://localhost:8000/Service/")                                       ' The address on wich the service will run.
            Dim NetTCPBaseAddress As Uri = New Uri("net.tcp://localhost:8001/Service/")
            Dim BaseAddresses As Uri() = {HttpBaseAddress, NetTCPBaseAddress}
            Host = New System.ServiceModel.ServiceHost(GetType(Core.Service), BaseAddresses)                            ' Create a new local service.
            Dim MetaDataBehavior As System.ServiceModel.Description.ServiceMetadataBehavior = Host.Description.Behaviors.Find(Of Description.ServiceMetadataBehavior)()       ' Create new metadata.

            If MetaDataBehavior Is Nothing Then
                MetaDataBehavior = New System.ServiceModel.Description.ServiceMetadataBehavior
                With MetaDataBehavior
                    .HttpsGetEnabled = True
                    .HttpGetEnabled = True
                End With
            End If
            Host.Description.Behaviors.Add(MetaDataBehavior)
            Host.AddServiceEndpoint(GetType(Core.IService), New System.ServiceModel.WSDualHttpBinding(), HttpBaseAddress)                                       ' Add the contract to the channel.
            Host.AddServiceEndpoint(GetType(Core.IService), New System.ServiceModel.NetTcpBinding(), NetTCPBaseAddress)
            Host.AddServiceEndpoint(Description.ServiceMetadataBehavior.MexContractName, Description.MetadataExchangeBindings.CreateMexHttpBinding(), "mex")    ' Add the metadata chennel to the service.
            Host.Open()
            Return True
        Catch ex As Exception
            Return False
        End Try

    End Function

    Public Shared Sub Close()
        If HostIsRunning() Then
            Host.Close()
            Host = Nothing
        End If
    End Sub

    Public Shared Function HostIsRunning() As Boolean
        Try
            Dim Client As New ServiceModel.Description.MetadataExchangeClient(New Uri("http://localhost:8000/Service/"), ServiceModel.Description.MetadataExchangeClientMode.HttpGet)
            Dim MData As ServiceModel.Description.MetadataSet = Client.GetMetadata
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
End Class
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #2  
Old 01-29-2014, 10:01 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

And the Client code

Code:
.
Namespace Global.System.GoggyInc.Wcf.Client
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0"),
    System.ServiceModel.ServiceContractAttribute(ConfigurationName:="IService",
    CallbackContract:=GetType(Global.System.GoggyInc.Wcf.Client.IServiceCallback), SessionMode:=System.ServiceModel.SessionMode.Required)> _
    Public Interface IService
        <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IService/Join", ReplyAction:="http://tempuri.org/IService/JoinResponse")> Sub Join(ByVal Name As String)
        <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IService/Join", ReplyAction:="http://tempuri.org/IService/JoinResponse")> Function JoinAsync(ByVal Name As String) As System.Threading.Tasks.Task
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/ChangeBackColor")> Sub ChangeBackColor(ByVal NewColor As System.Drawing.Color)
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/ChangeBackColor")> Function ChangeBackColorAsync(ByVal NewColor As System.Drawing.Color) As System.Threading.Tasks.Task
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/ChangeServerPath")> Sub ChangeServerPath(ByVal NewPath As String)
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/ChangeServerPath")> Function ChangeServerPathAsync(ByVal NewPath As String) As System.Threading.Tasks.Task
    End Interface
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
    Public Interface IServiceCallback
        <System.ServiceModel.OperationContractAttribute(Action:="http://tempuri.org/IService/NotifyMemberJoined", ReplyAction:="http://tempuri.org/IService/NotifyMemberJoinedResponse")> Sub NotifyMemberJoined(ByVal Name As String)
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/NotifyBackcolorChanged")> Sub NotifyBackcolorChanged(ByVal Color As System.Drawing.Color)
        <System.ServiceModel.OperationContractAttribute(IsOneWay:=True, Action:="http://tempuri.org/IService/NotifyServerPathChanged")> Sub NotifyServerPathChanged(ByVal NewPath As String)
    End Interface
    <System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
    Public Interface IServiceChannel
        Inherits Global.System.GoggyInc.Wcf.Client.IService, System.ServiceModel.IClientChannel
    End Interface
    <System.Diagnostics.DebuggerStepThroughAttribute(), System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")> _
    Partial Public Class ServiceClient
        Inherits System.ServiceModel.DuplexClientBase(Of Global.System.GoggyInc.Wcf.Client.IService)
        Implements Global.System.GoggyInc.Wcf.Client.IService

        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext)
            MyBase.New(callbackInstance)
        End Sub
        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String)
            MyBase.New(callbackInstance, endpointConfigurationName)
        End Sub
        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String, ByVal remoteAddress As String)
            MyBase.New(callbackInstance, endpointConfigurationName, remoteAddress)
        End Sub
        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal endpointConfigurationName As String, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
            MyBase.New(callbackInstance, endpointConfigurationName, remoteAddress)
        End Sub
        Public Sub New(ByVal callbackInstance As System.ServiceModel.InstanceContext, ByVal binding As System.ServiceModel.Channels.Binding, ByVal remoteAddress As System.ServiceModel.EndpointAddress)
            MyBase.New(callbackInstance, binding, remoteAddress)
        End Sub
        Public Sub Join(ByVal Name As String) Implements Global.System.GoggyInc.Wcf.Client.IService.Join
            MyBase.Channel.Join(Name)
        End Sub
        Public Function JoinAsync(ByVal Name As String) As System.Threading.Tasks.Task Implements Global.System.GoggyInc.Wcf.Client.IService.JoinAsync
            Return MyBase.Channel.JoinAsync(Name)
        End Function
        Public Sub ChangeBackColor(ByVal NewColor As System.Drawing.Color) Implements Global.System.GoggyInc.Wcf.Client.IService.ChangeBackColor
            MyBase.Channel.ChangeBackColor(NewColor)
        End Sub
        Public Function ChangeBackColorAsync(ByVal NewColor As System.Drawing.Color) As System.Threading.Tasks.Task Implements Global.System.GoggyInc.Wcf.Client.IService.ChangeBackColorAsync
            Return MyBase.Channel.ChangeBackColorAsync(NewColor)
        End Function
        Public Sub ChangeServerPath(ByVal NewPath As String) Implements Global.System.GoggyInc.Wcf.Client.IService.ChangeServerPath
            MyBase.Channel.ChangeServerPath(NewPath)
        End Sub
        Public Function ChangeServerPathAsync(ByVal NewPath As String) As System.Threading.Tasks.Task Implements Global.System.GoggyInc.Wcf.Client.IService.ChangeServerPathAsync
            Return MyBase.Channel.ChangeServerPathAsync(NewPath)
        End Function
    End Class

    Public Class Client
        Private m_Service As ServiceClient = Nothing

        Public Sub New(Caller As Core.FrmBase)
            Dim HttpBinding As New System.ServiceModel.WSDualHttpBinding
            Dim TcpBinding As New System.ServiceModel.NetTcpBinding
            Dim Endpoints As EndpointAddress() = {New EndpointAddress(New Uri("http://localhost:8000/Service/")), New EndpointAddress(New Uri("net.tcp://localhost:8001/Service/"))}
            With HttpBinding
                .OpenTimeout = New TimeSpan(0, 0, 0, 10)
                .CloseTimeout = .OpenTimeout
                .ReceiveTimeout = New TimeSpan(0, 0, 0, 10)
                .SendTimeout = .ReceiveTimeout
            End With
            With TcpBinding
                .OpenTimeout = New TimeSpan(0, 0, 0, 10)
                .CloseTimeout = .OpenTimeout
                .ReceiveTimeout = New TimeSpan(0, 0, 0, 10)
                .SendTimeout = .ReceiveTimeout
            End With
            m_Service = New ServiceClient(New ServiceModel.InstanceContext(Caller), New System.ServiceModel.WSDualHttpBinding, Endpoints(0)) '"TcpBinding") '
        End Sub
        Public Property Service() As ServiceClient
            Get
                Return m_Service
            End Get
            Set(ByVal value As ServiceClient)
                m_Service = value
            End Set
        End Property

        Public Sub Open()
            If m_Service IsNot Nothing Then
                m_Service.Open()
            End If
        End Sub
    End Class
End Namespace
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #3  
Old 01-29-2014, 10:03 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

I fiddled around with the protocol timeouts... setting them any where from minutes till miliseconds but to no help. In the code above there still on miliseconds...

I should also mention, this is my first attempt at using WCF so please be gentle with me if i made a enormous blunder. :P
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
  #4  
Old 01-29-2014, 10:27 AM
Goggy's Avatar
Goggy Goggy is offline
Contributor
 
Join Date: Sep 2005
Location: Enschede,The Netherlands
Posts: 670
Default

Sorry People for making you all read the long post,
The problem is solved was calling the the wrong methode in my client side code... i was calling the "Join" methode when i should have been calling the "JoinAsync" methode... now the all runs like a dream...

Thank you again for your time and efforts..

With best regards.
Me!
__________________
As finishing touch, god created the Dutch!

utterly useless, but always trying to help
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
 
Windows Communication Foundation in one Class
Windows Communication Foundation in one Class
 
-->