Custom WCF Service configuration

Check Windows Authentication section for sample configuration which can be used in web.config.

Windows Authentication

  1. Enable windows authentication in IIS
  2. Create configuration in web.config

 <system.serviceModel>
   <bindings>
      <webHttpBinding>
        <binding name="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService">
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="Windows"/>
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webScriptBehavior">
          <enableWebScript />
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
          <!--<serviceDebug includeExceptionDetailInFaults="true" />-->
          <serviceAuthorization principalPermissionMode="UseWindowsGroups" />
        </behavior>
      </serviceBehaviors>
    </behaviors>    
    <services>
      <service name="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService" 
               behaviorConfiguration="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyServiceBehavior">
        <endpoint contract="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService"
                  binding="webHttpBinding" bindingConfiguration="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService"
                  behaviorConfiguration="webScriptBehavior"/>
      </service>
    </services>
  </system.serviceModel>

Troubleshooting

Web.config

<add name="SvcHandler" path="*.svc" verb="*" 
         type="System.ServiceModel.Activation.HttpHandler, System.ServiceModel,  Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"  />

For .Net 4.0/4.5 try adding
<bindings>
  <webHttpBinding>
    <binding name="RESTServiceBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
      <readerQuotas maxStringContentLength="1048576" />
    </binding>
  </webHttpBinding>
</bindings>

<service name="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService">
  <endpoint address="" binding="webHttpBinding" bindingConfiguration="RESTServiceBinding" contract="MakingWaves.Common.EPiServer.CustomProperties.ImageProperties.ImagePropertyService" />
</service>

Application changes

Somewhere in application setup (e.g. Application_Start in Global.asax)

AssemblyResourceVirtualPathProvider.EnsureRegistered();

BasicResolver resolver = new BasicResolver();

IImageTransformationService imageTransformationService = new ImageTransformationService(
    //use EPiServer infrastructure as source for scaled image     
    new MixedVirtualFileSystem().Add(new EPiServerFileSystem()).Add(new LocalFileSystem()),
    //Saved scaled images under "Images/Scaled" folder in web site                    
    new LocalVirtualPathStore(Url.Parse("~/Images/Scaled")));
//register image transformation service to override default
resolver.Register<IImageTransformationService>(imageTransformationService);

ServiceLocator.SetResolver(resolver);

WCF registration

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i -enable
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -i -enable


"C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg" -i
"C:\Windows\Microsoft.NET\Framework64\v3.0\Windows Communication Foundation\ServiceModelReg" -i

IIS authentication schemes

In case of error:

IIS specified authentication schemes 'IntegratedWindowsAuthentication, Anonymous', but the binding only supports specification of exactly one authentication scheme. Valid authentication schemes are Digest, Negotiate, NTLM, Basic, or Anonymous. Change the IIS settings so that only a single authentication scheme is used.

check Windows Authentication section

Last edited Feb 6, 2014 at 11:08 AM by mjedynak, version 9

Comments

No comments yet.