none
WCF Service with Basic Authentication and Windows Authentication RRS feed

  • Question

  • Hi,

    I have one WCF project with 8 SVC file. I want out of 8 , 4 will be Windows Authentication and 4 will be Basic Authentication.

    Under same project.

    Can we set Mixed Authentication for single IIS Project have different SVC file.

    Thanks

    Abhishek

    Wednesday, January 24, 2018 9:51 AM

All replies

  • Hi Abhishek,

    >> Can we set Mixed Authentication for single IIS Project have different SVC file.

    Yes, you can.

    A simple demo like below:

    1. WCF Configuration

      <system.serviceModel>
        <services>
          <service name="WCFMultipleAuth.Service1">
            <endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="basic" contract="WCFMultipleAuth.IService1" />
          </service>
          <service name="WCFMultipleAuth.Service2">
            <endpoint address="windows" binding="basicHttpBinding" bindingConfiguration="windows" contract="WCFMultipleAuth.IService2"/>
          </service>
        </services>
        <bindings>
          <basicHttpBinding>
            <binding name="basic">
              <security mode="Transport">
                <transport clientCredentialType="Basic"/>
              </security>
            </binding>
            <binding name="windows">
              <security mode="Transport">
                <transport clientCredentialType="Windows"/>
              </security>
            </binding>
          </basicHttpBinding>
        </bindings>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    2. IIS Configuration

    3. Client Configuration

        <system.serviceModel>
            <bindings>
                <basicHttpBinding>               
                    <binding name="BasicHttpBinding_IService13">
                        <security mode="Transport">
                            <transport clientCredentialType="Basic" />
                        </security>
                    </binding>
                    <binding name="BasicHttpBinding_IService2">
                        <security mode="Transport">
                            <transport clientCredentialType="Windows" />
                        </security>
                    </binding>
                </basicHttpBinding>
            </bindings>
            <client>            
                <endpoint address="https://xxx/WCFMultipleAuth/Service1.svc/basic"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService13"
                    contract="WCFMultipleAuth_Basic.IService1" name="BasicHttpBinding_IService13" />
                <endpoint address="https://xxx/WCFMultipleAuth/Service2.svc/windows"
                    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService2"
                    contract="WCFMultipleAuth_Windows.IService2" name="BasicHttpBinding_IService2" />
            </client>
        </system.serviceModel>

    4. Client Code

            private void WCFBasic_Click(object sender, EventArgs e)
            {
                WCFMultipleAuth_Basic.Service1Client client = new WCFMultipleAuth_Basic.Service1Client();
                client.ClientCredentials.UserName.UserName = "domain/user";
                client.ClientCredentials.UserName.Password = "password";
                string result = client.GetData(123);
                MessageBox.Show(result);
            }
    
            private void WCFWindows_Click(object sender, EventArgs e)
            {
                WCFMultipleAuth_Windows.Service2Client client = new WCFMultipleAuth_Windows.Service2Client();
                string result = client.DoWork();
                MessageBox.Show(result);
            }

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Friday, January 26, 2018 3:20 AM