Executes WS from the server with the client credentials

Hi,

I have a sikverlight 4 intranet application with RIA services.
I have a webservice (.asmx) which my application references as a WCF service.
I need that the WS will be executed from the server, but using the client credentials and not the server credentials. I somehow need to impersonate as the client. The server and the client are both in the same LAN and domain.
My question is how do I do this?

Enviroment:
Windows 7, IIS 7.5, Visual Studio 2010, Silverlight 4

My web server class that calls the WS looks like this:

    [EnableClientAccess()]
    public class DemographyDomainService : DomainService
    {

        public void GetDemography()
        {
            CustomersService.CustomersServiceClient srv = new CustomersService.CustomersServiceClient();
            CustomersService.CustomersRequest req = new tCustomersService.CustomersRequest();

            CustomersService.CustomersResponse response = srv.CustomersQuery(req);

        }

    }


My web.config looks like this;
<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
            <add name="DomainServiceModule" preCondition="managedHandler"
                type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
    </system.webServer>
    <system.web>
        <httpModules>
            <add name="DomainServiceModule" type="System.ServiceModel.DomainServices.Hosting.DomainServiceHttpModule, System.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </httpModules>
        <compilation debug="true" targetFramework="4.0" />
        <authentication mode="Windows"/>
    </system.web>

    <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
            multipleSiteBindingsEnabled="true" />
        <bindings>
            <basicHttpBinding>
                <binding name="CustomersService" closeTimeout="00:01:00"
                    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                    maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                    useDefaultWebProxy="true">
                    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                    <security mode="None">
                        <transport clientCredentialType="None" proxyCredentialType="None"
                            realm="" />
                        <message clientCredentialType="UserName" algorithmSuite="Default" />
                    </security>
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://myurl:8089/Customers/CustomersService.asmx"
                binding="basicHttpBinding" bindingConfiguration="CustomersService"
                contract="CustomersService.CustomersService" name="CustomersService" />
        </client>
    </system.serviceModel>
</configuration>

ruvikAsked:
Who is Participating?
 
ruvikAuthor Commented:
It was a problem with the web.config.
I changed the web.config and now it works.

Web.Config

<basicHttpBinding>
      <binding name="CustomersService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
            maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
            useDefaultWebProxy="true">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <security mode="TransportCredentialOnly">
                  <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
                  <message clientCredentialType="UserName" algorithmSuite="Default" />
            </security>
      </binding>
</basicHttpBinding>

<service name="SLWCF.Web.Demography">
      <endpoint address="" binding="customBinding" bindingConfiguration="CustomBinding"
            contract="SLWCF.Web.Demography" />
</service>


ClientConfig:

<bindings>
      <customBinding>
            <binding name="CustomBinding">
                  <binaryMessageEncoding />
                  <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
            </binding>
      </customBinding>
</bindings>
<client>
      <endpoint address="../Demography.svc" binding="customBinding"
            bindingConfiguration="CustomBinding" contract="Demography"
      name="CustomBinding_Demography" />
</client>

Turn off Anonymous Authentication
Turn on Windows Authentication
0
 
ruvikAuthor Commented:
I forgot to mention that when I reference the web service as a web reference then I'm able to do exactly what I need using this code;

using( CustomersService service = new CustomersService() )
                {
                    service.Credentials = System.Net.CredentialCache.DefaultCredentials;
                    response = service.CustomersQuery();
                }

I need this code for a WCF service.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.