I am attempting to pass a string into a method and based on what string is passed in, either instantiate BasicHttpBinding or WSHttpBinding. The following if statement is in my code.

```
if(bindingObject == "basic")
{System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();}
else
{System.ServiceModel.WSHttpBinding binding = new System.ServiceModel.WSHttpBinding();

```

This code gives me the error

> 
> The name 'binding' does not exist in the current context
> 
> 
> 

From my research it seems I have to use a common base class between the two service models if I want to use the variable named *binding* no matter which ServiceModel I need to use.

My question is, what is the common base class that would work? Or is there a way to do this. The closest I have found is System.ServiceModel.Channels.Binding but then I get the error such as

> 
> does not contain a definition for 'MaxBufferPoolSize' and no extension method 'MaxBufferPoolSize' accepting a first argument of tyep 'System.ServiceModel.Channels.Binding' could be found
> 
> 
>
['https://Stackoverflow.com/questions/36802272', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3150921/']
First: both `BasicHttpBinding` and `BasicHttpBinding` need to either derive from the same base class or implement the same [interface](https://msdn.microsoft.com/en-us/library/87d83y5b.aspx) 

If you're using visual studio, you can put a cursor over the types and press `f12` to see what types they derive from and what interfaces they implement. The type that is appropriate to use depends on what you want to do with them. 

According to documentation for [BasicHttpBinding](https://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpbinding%28v=vs.110%29.aspx) and [WSHttpBinding](https://msdn.microsoft.com/en-us/library/system.servicemodel.wshttpbinding%28v=vs.110%29.aspx), the common base class seems to be `System.ServiceModel.Channels.Binding`, 

**You should use `f12` to check anyway, because there's probably an interface in there that defines the members that you need to use.**

Second, You have to declare it outside the context of your if statement

```
System.ServiceModel.Channels.Binding binding;
if(bindingObject == "basic")
{
    binding = ...
}
else
{
    binding = ...
}

```
You could use wither the Binding base class or the IBindingRuntimePreferences interface, if that provides access to the functionality you need.

```
   //System.ServiceModel.Channels.Binding binding;
    System.ServiceModel.Channels.IBindingRuntimePreferences binding;
    if(bindingObject == "basic")
       binding = new System.ServiceModel.BasicHttpBinding();}
    else
       binding = new System.ServiceModel.WSHttpBinding();

```