Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a service

C#
[ServiceContract]
public interface IUtility
{
    [OperationContract]
    int Multiply(int a,int b);
}


public class Utility : IUtility
{
      int Multiply(int a,int b)
      {
           return a*b;    
      }
}


now i want to consume this service async in my c# windows application through code without adding service reference only through programatically.
Posted
Updated 7-Jul-12 0:46am
v2

 
Share this answer
 
You can do this.
You can create proxy of a service using ChannelFactory class. You dont have to refer to the service. while adding reference to your wcf service what visual studio does is to create a proxy and edit the client config file to add end points so that proxy can use it.

ChannelFactory class has constructors which accepts ServiceEndpoint. This can be the endpoint name from the client config file.

After creating object of channel factory, you can call
C#
CreateChannel()
method which will give you the proxy. After creating the proxy, you can call your service methods using this proxy.

C#
ChannelFactory<IMyContract> factory = new ChannelFactory<IMyContract>();
IMyContract proxy = factory.CreateChannel();
proxy.Method1();
proxy.Close();


But before, you need to add the configurations to the client config file. Address Endpoints bindings and all. After doing this you should be able to do as in code.

Hope this helps.
 
Share this answer
 
v10
Comments
agha_ali22 6-Jul-12 9:20am    
i want to do the method call async e.g
method1begin(......)
metod1end(.......)
agha_ali22 6-Jul-12 9:22am    
actually i have two client app one in Silverlight which is working perfectly now i want to build a desktop app using same service.(async pattern)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900