WCF Winform freezes when opened by server

64 views Asked by At

I've written a VSTO Outlook Add-In and am trying to open a form in a separate Winform app when the user pushes a button on the Add-In, passing an integer as argument. I'm using WCF Named Pipe Binding. The Add-In is the client and the Winform app is the server. The binding and inter-process communication works fine. However, when the target form opens, it freezes with a spinning cursor. The form otherwise works fine from within the Winform app.

Per the code below, when I call "clsActivity.EditT("", activityID);" within the server method, it opens a form which is properly created and displayed, but then locks up with a spinning cursor and is inaccessible. I've been assuming that there is some element of the servicehost or other WCF process that is uncompleted, but can't identify the issue.

I've spent several days trying to find an answer. As I'm pretty new to WCF, I'm not even sure if I'm asking the right questions. Any assistance would be greatly appreciated. Thanks.

Server

// Service Contract
[ServiceContract(Namespace = "ComsIPC")]
interface ComsIPCContract
{
    [OperationContract(IsOneWay = true)]
    void OpenActivity(int activityID);
}

// Server Implementation
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class ComsIPCServer : ComsIPCContract
{
    public void OpenActivity(int activityID)
    {
        try
        {
            clsActivity.EditT("", activityID);
        }
        catch
        {
            MessageBox.Show("Error in ComsIPCServer");
        }
    }

    public void CreateComsIPCServerHost()
    {
        string address = "net.pipe://localhost/coms/IPC";

        ServiceHost serviceHost = new ServiceHost(typeof(ComsIPCServer));
        NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
        serviceHost.AddServiceEndpoint(typeof(ComsIPCContract), binding, address);
        serviceHost.Open();
    }
}

Client

// Service Contract
[ServiceContract(Namespace = "ComsIPC")]
interface ComsIPCContract
{
    [OperationContract(IsOneWay = true)]
    void OpenActivity(int activityID);
}

public class ComsIPCClient
{
    public void OpenActivityInComs(int activityID)
    {
        string address = "net.pipe://localhost/coms/IPC";

        NetNamedPipeBinding binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None);
        EndpointAddress ep = new EndpointAddress(address);
        ComsIPCContract channel = ChannelFactory<ComsIPCContract>.CreateChannel(binding, ep);

        channel.OpenActivity(activityID);
    }
}
0

There are 0 answers