Jesuraja
Jesuraja

Reputation: 3844

How to call WCF Service overloaded constructors in client

I am new to WCF. I created two overloaded constructor in WCF service. I added reference of WCF Service in my client application. I can able to call the WCF methods from the client. But I dont know,

How to call the overloaded constructors from client? Is it possible?.

I searched for the same, I looked some answers, but I am not able to understand the things clearly, as I new to this. I am looking for straight forward simple example to call the WCF constructors.

It will be helpful, if anyone provide a example link for reference.

Upvotes: 1

Views: 1657

Answers (3)

John Saunders
John Saunders

Reputation: 161791

A SOAP service never exposes anything that it specific to the .NET platform. That includes constructors.

Keep in mind that anything exposed by a SOAP service is exposed by describing it in the WSDL. There is no way to describe in the WSDL:

  1. constructors
  2. events
  3. indexers
  4. generics

etc.

Upvotes: 1

Rabi
Rabi

Reputation: 2220

you should be able to do it. A little understanding on how WCF instance managed is required.

Theory :

  1. when a WCF service is invoked, a new instance is created per call by default (see InstanceContextMode) by the service dispatcher.

  2. a call to GetInstance() and ReleaseInstance() (of IInstanceProvider) is made to instantiate and release the service object respectively (except when InstanceContextMode is Single) depending up the InstanceContextMode .

  3. In above scenario, the default constructor is invoked.

  4. WCF provides extensibility point where you can inject your own instance provider (so that you'll be able to call the overloaded constructor).

Action :

  1. create a new Instance Provider by inheriting from IInstanceProvider. Override GetInstance() and ReleaseInstance() methods. on GetInstance() method use your overloaded constructore to return a new service instance.

  2. create a new Service Behavior (say InstanceProviderBehavior) attribute (by inherting from Attribute and IServiceBehavior) to apply on service contract so that service dispatcher looks for your own custom Instance Provider.

Here is a great article - http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx

Upvotes: 0

Marcel N.
Marcel N.

Reputation: 13976

As I said, the services are instantiated server-side by the framework. You only have access to a generated proxy which under the hood connects to your service.

Anyway, what you want is not doable via service constructors. If you have a business object then pass that to a service operation:

using(var serviceClient = new MyServiceClient())
{
   serviceClient.SomeOperation(businessObject);
}

The constructor you see here for MyServiceClient has absolutely no relation to the constructor you defined for the service contract.

Also, you may want to look into service instancing modes as it seems to me you don't want a per-call mode.

Upvotes: 0

Related Questions