Monday, December 21, 2015

Features of Windows Communication Foundation v4.5 part 2:

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 ContractClient 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


0 comments:

Thanks for commenting..,,

Copyright © 2016 CodeSharing| Design by CodingSharing.