Monday, December 21, 2015

Simplified Generated Configuration:
As simplified config files were introduced that had the concepts of default bindings and default endpoints - meaning that you could create an out-of-the-box WCF service application in 4.0 or 4.5 and there would be no binding or endpoint defined - you can verify this by looking at the web.config files for your 4.0 and 4.5 service.

When you add a service reference, you most likely used an "http://" URI - by default, "http" maps to basicHttpBinding. So let's look at the snippet you posted in the comments:
<endpoint address="localhost:36275/Service1.svc"
           binding="basicHttpBinding" 
           bindingConfiguration="BasicHttpBinding_IService1"
           contract="ServiceReference1.IService1" 
           name="BasicHttpBinding_IService1" />
Everything the client needs to communicate with the service is there - the address, the binding to use, the binding configuration to use and the contract.
If you look in the client config file, you should see the following as well:
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" />
  </basicHttpBinding>
</bindings>
Which corresponds to the binding specified by the endpoint's bindingConfiguration attribute. Since the defaults are being used, the other properties for the binding are not specified.
In 3.0 and 3.5, the binding section would have had all the properties of the binding specified with default values - in 4.0 and later it does not.
You're not missing anything - other than the documentation being a little misleading in that it implies this is a 4.5 feature, when it reality it's a 4.0 and 4.5 feature.
Validating WCF service:
It provides warning messages to the user when an input string is not in the correct format in a XML file".
The complete code of web.config looks like this:
<?xml version="1.0"?>
<configuration>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:4164/Service1.svc" binding="basicHttpBinding"contract="WCFApp.IService1" bindingConfiguration="BasicHttpBinding_IService1"name="BasicHttpBinding_IService1"/>
    </client>
  </system.serviceModel>
  <system.web>
    <compilation debug="true"/>
  </system.web>
</configuration>
 

The output of configuration validation error looks like this:

1)    Self-hosting:
          Self-hosting bit differ because there is no IIS in the picture to inherits setting from. Here you just set the setting in <serviceAuthenticationManager> or serviceAuthenticationBehaviour .

// ...
ServiceAuthenticationBehavior sab = null;
sab = serviceHost.Description.Behaviors.Find<ServiceAuthenticationBehavior>();
if (sab == null)
{
    sab = new ServiceAuthenticationBehavior();
    sab.AuthenticationSchemes = AuthenticationSchemes.Basic | AuthenticationSchemes.Negotiate | AuthenticationSchemes.Digest;
    serviceHost.Description.Behaviors.Add(sab);
}
else
{
  sab.AuthenticationSchemes = AuthenticationSchemes.Basic | AuthenticationSchemes.Negotiate | AuthenticationSchemes.Digest;
}
// ...
In config , it looks follows:
<behaviors>
      <serviceBehaviors>
        <behavior name="limitedAuthBehavior">
          <serviceAuthenticationManager authenticationSchemes="Negotiate, Digest, Basic"/>
          <!-- ... -->
        </behavior>
      </serviceBehaviors>
    </behaviors>

And then you can specify InheritFromHost in your binding settings as shown in the following XML snippet.
<bindings>
      <basicHttpBinding>
        <binding name="secureBinding">
          <security mode="Transport">
            <transport clientCredentialType="InheritedFromHost" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
Alternatively, you can specify the authentication schemes in a custom binding, by setting the authentication schemes on the HTTP transport binding element, as shown in the following config snippet.

<binding name="multipleBinding">
      <textMessageEncoding/>
      <httpTransport authenticationScheme="Negotiate, Ntlm, Digest, Basic" />
    </binding>

Contract first development:
As we know that with previous versions of Windows Communication Foundation, while creating proxy using SvcUtil.exe tool, the output generated file contains the Service Contract, Client operations as well as Data Contracts. There was no way to generate the Service Contract only. But with Windows Communication Foundation v4.5, now it’s possible to generate the Service Contract only using SvcUtil.exe tool as follows:
svcutil.exe “http://localhost:MyFirstWCFService/Service1.svc?wsdl” /serviceContract


ñ  Multiple Authentication Support
ñ  Contract First Development
ñ  Simplified Generated Configuration
ñ  Validating WCF Configuration
ñ  Single WSDL file
ñ  Tooltip and Intellisense Support
ñ  ASP.NET Compatibility Mode default change
ñ  BasicHttpsBinding
ñ  Task-based Programming Model
ñ  ChannelFactory Caching

Multiple Authentication Support:
      WCF 4.0 allows to multiple authentication on a single endpoint and we can sustain further inherited their authentication directly from IIS or self-hosting.

1)    IIS Hosting :
For IIS host services set the property of authentication schemas as per the requirements. Then in your service’s  in web.config file set the ‘clientCredentialType’  as “InheritedFromHost”.

In Web.Config:
<bindings>
      <basicHttpBinding>
        <binding name="secureBinding">
          <security mode="Transport">
            <transport clientCredentialType="InheritedFromHost" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>

You can specify that only subset of authentication schemas to be used with your service using ServiceAuthenticationBehaviour or the <serviceAuthenticationManager> element.
Code Snippet:
ServiceAuthenticationBehavior sab = null;
sab = serviceHost.Description.Behaviors.Find<ServiceAuthenticationBehavior>();
if (sab == null)
{
    sab = new ServiceAuthenticationBehavior();
    sab.AuthenticationSchemes = AuthenticationSchemes.Basic | AuthenticationSchemes.Negotiate | AuthenticationSchemes.Digest;
    serviceHost.Description.Behaviors.Add(sab);
}
else
{
     sab.AuthenticationSchemes = AuthenticationSchemes.Basic | AuthenticationSchemes.Negotiate | AuthenticationSchemes.Digest;
}
 
                                 When configuration this in a config file , use the  <serviceAurhtenticationManager>
Shown in the following.
<behaviors>
      <serviceBehaviors>
        <behavior name="limitedAuthBehavior">
          <serviceAuthenticationManager authenticationSchemes="Negotiate, Digest, Basic"/>
          <!-- ... -->
        </behavior>
      </serviceBehaviors>
         </behaviors>


Copyright © 2016 CodeSharing| Design by CodingSharing.