Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChannelFactory<T> without interface

Tags:

c#

soap

wcf

I am currently trying to create a REST proxy that calls a WCF SOAP service, I am stuck trying to make a channel to send the message through. I know I need to use ChannelFactory, but I don't have the interface of the service. Is there a default value I can pass? Is there another way to package the message?

When I say message, I mean one from ServiceModels.Channels.Message.

I'm very new to this so any help would be appreciated.

like image 971
SmashCode Avatar asked Feb 22 '23 10:02

SmashCode


1 Answers

You can generate a WCF client from a WSDL service contract in one of two ways:

  • Using the Add Service Reference dialog in Visual Studio
  • Using the svcutil command line utility

Either way will generate .NET classes that correspond to the types exposed by the service contract as well as a WCF client proxy class, which you can use to invoke the service operations:

try
{
    var client = new MyServiceClient();
    client.DoSomething();
    client.Close();
}
catch
{
    if (client != null)
    {
         client.Abort();
    }
}

If you prefer to use the lower level ChannelFactory API, you should use the generated IClientChannel interface instead:

try
{
    var factory = new ChannelFactory<MyServiceChannel>();
    var client = factory.CreateChannel();
    client.DoSomething();
    client.Close();
}
catch
{
    if (client != null)
    {
         client.Abort();
    }
}
like image 55
Enrico Campidoglio Avatar answered Feb 26 '23 21:02

Enrico Campidoglio