locked
Wcf Service RRS feed

  • Question

  • Hello,

    I am using a wcf service to implement some functionality and deployed at our server.

    Now i want to consume that service in one of my plugin. The problem is that I want to invoke the method without adding the service reference , because my Service URL will vary based on the enviorment I am using.

    Is there any way to invoke the method without adding the service reference.

    I have Tried out the channel factory but Not able to access the method.

    This is the piece of code i was trying, Please Help !! I am new in wcf services.

    BasicHttpBinding binding = new BasicHttpBinding();
       //EndpointAddress address = new EndpointAddress("// (String)SERVICE URL");
       var factory = new ChannelFactory<IRequestChannel>(binding, new EndpointAddress("// (String)SERVICE URL");

     //   IRequestChannel channel = factory.CreateChannel();
       channel.ProcessMethod("param1", " param2 ");

    Thursday, July 12, 2012 7:01 AM

All replies

  • You can add a Service Reference and specify the URL dynamically.  When the Service Reference is added, a Client class is generated, e.g. MyServiceClient.  The Client class has several constructors, one of which can take an address and binding as parameters:

    public CalculatorClient(System.ServiceModel.EndpointAddress address, System.ServiceModel.Binding binding) : base(address, binding) {}
    http://msdn.microsoft.com/en-us/library/ms734691.aspx


    --pogo (pat) @ pogo69.wordpress.com

    Thursday, July 12, 2012 8:28 AM
  • As Pat said, you can add a service reference and change the endpoint dynamically (for example from a config value somewhere in CRM) - alternatively you could implement a REST-based service instead.
    Monday, July 16, 2012 8:54 PM