0

I would like our WCF service to return the the current logged in user's name. I am calling this in my service,

HttpContext.Current.User.Identity.Name

However, I don't want the user to be shown a NT challenge when my silverlight application makes a call to the WCF service. Currently I disabled anonymous access and enabled integrated authentication however, due to this I am not able to add the service to my service reference in VS2010. How do I do it? Also what should be the web.config settings for the WCF service. I am currently using basicHttpBinding with security mode set to None.

Adding Web.config: Server:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<behaviors>
<serviceBehaviors>
<behavior name="MyService.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" receiveTimeout="00:40:00" openTimeout="00:40:00" closeTimeout="00:40:00" sendTimeout="00:40:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<security mode="None"/>
</binding>
</basicHttpBinding>
<customBinding>
<binding name="MyService.MyService.customBinding0">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service behaviorConfiguration="MyService.MyServiceBehavior" name="MyService.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService" name="BasicHttpBinding_MyService" contract="MyService.IMyService"/>
</service>
</services>
</system.serviceModel>

Client:

<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
<behaviors>
<serviceBehaviors>
<behavior name="MyService_Behavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="r1">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_MyService" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<security mode="None"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/MyService/MyService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_MyService" contract="MyService.IMyService" name="BasicHttpBinding_MyService" behaviorConfiguration="r1"/>
</client>
</system.serviceModel>
Kev
  • 3
  • 1
  • 5

2 Answers2

0

Try adding the following, endpoint behavior to you end point, with the psudo client config below

<behaviors>
    <endpointBehaviors>
        <behavior name="WindowsBehavior">
            <clientCredentials>
                <windows allowNtlm="false" allowedImpersonationLevel="Delegation"></windows>
            </clientCredentials>
            <dataContractSerializer maxItemsInObjectGraph="4194304"></dataContractSerializer>
        </behavior>
    </endpointBehaviors>
</behaviors>


<endpoint address="http://server/web.svc" behaviorConfiguration="WindowsBehavior" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Service" contract="IMyContract" name="BasicHttpBinding_Service">
vrajs5
  • 4,066
  • 1
  • 27
  • 44
Iain
  • 6,392
  • 2
  • 30
  • 50
0

you need to enable windows authentiacation in the service binding config. i.e. reference this binding cinfig in you binding definition section

<bindings>
      <basicHttpBinding>
          <binding name="basicBindingCfg">
              <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Windows" />
              </security>
          </binding>
      </basicHttpBinding>
  </bindings>

also in you web config you need to set windows authentication

and allow users using the authorization tag:

   <authentication mode="Windows"/>
   <authorization>
        <allow roles="<NT group>"/>
        <allow users="<user name>"/>
        <deny users="*"/>
    </authorization>
Menahem
  • 3,974
  • 1
  • 28
  • 43