none
how to ask user credential when adding service RRS feed

  • Question

  • hi ;

    I am developing a service ,I want to configure a service like below

    when somebody want to add a service in visual studio ,I want to ask a credential like username and password



    Wednesday, May 6, 2020 8:27 PM

Answers

  • Hi,

    At first, we should enable windows authentication in IIS authentication module. Make sure that other authentications are disabled, only windows authentication is enabled.
    https://i.stack.imgur.com/iHaeD.png
    Then refer to the below configuration.

    <system.serviceModel>
            <services>
                <service name="WcfService1.Service1">
    				<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" ></endpoint>
                </service>
            </services>
    		<bindings>
    			<basicHttpBinding>
    				<binding>
    					<security mode="Transport">
    						<transport clientCredentialType="Windows"></transport>
    					</security>
    				</binding>
    			</basicHttpBinding>
    		</bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        </system.serviceModel>
    


    Finally, please add an https binding URL in the IIS site binding module.
    https://i.stack.imgur.com/S3JHw.png
    Result.
    https://i.stack.imgur.com/zhLUw.png
    This works as same as Basic authentication. 

    <binding>
    <security mode="Transport">
    <transport clientCredentialType="Basic"></transport>
    </security>
    </binding>


    Username might be unfeasible, I am sorry for my preceding declare.
    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham

      
    • Marked as answer by Aly14 Friday, May 8, 2020 12:58 PM
    Friday, May 8, 2020 6:58 AM
    Moderator

All replies

  •   

    Hi,
    As long as we authenticates the client with windows credential/username, the client will be prompted to input username/password when adding service reference.  this can be achieved in the binding configuration.

               BasicHttpBinding binding = new BasicHttpBinding();
                binding.Security.Mode = BasicHttpSecurityMode.Transport;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                // or username authentication.
                //binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
                //binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;

    This is determined by your binding configuration on the server-side. I would like more details about it and give an effective reply.

    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham


    Thursday, May 7, 2020 3:26 AM
    Moderator
  • hi;

    I configured the details in web.config like below , How to change this with your advice

     <httpRuntime targetFramework="4.5" executionTimeout="9999" maxRequestLength="16384"/>
        <identity impersonate="true" />
      </system.web>
      <system.serviceModel>
        <bindings />
        <client />
        <behaviors>
          <serviceBehaviors>
            <behavior name="servicebehaviors">
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior name="web">
              <webHttp />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="servicebehaviors" name="Microsoft_NetFramework_v5.WebApi">      
            <endpoint address="lom" behaviorConfiguration="" binding="basicHttpBinding" contract="Microsoft_NetFramework_v5.IWebApi" />
          </service>
        </services>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
    </configuration>

    Thursday, May 7, 2020 10:35 AM
  • Hi,

    At first, we should enable windows authentication in IIS authentication module. Make sure that other authentications are disabled, only windows authentication is enabled.
    https://i.stack.imgur.com/iHaeD.png
    Then refer to the below configuration.

    <system.serviceModel>
            <services>
                <service name="WcfService1.Service1">
    				<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" ></endpoint>
                </service>
            </services>
    		<bindings>
    			<basicHttpBinding>
    				<binding>
    					<security mode="Transport">
    						<transport clientCredentialType="Windows"></transport>
    					</security>
    				</binding>
    			</basicHttpBinding>
    		</bindings>
            <behaviors>
                <serviceBehaviors>
                    <behavior>
                        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>
            <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        </system.serviceModel>
    


    Finally, please add an https binding URL in the IIS site binding module.
    https://i.stack.imgur.com/S3JHw.png
    Result.
    https://i.stack.imgur.com/zhLUw.png
    This works as same as Basic authentication. 

    <binding>
    <security mode="Transport">
    <transport clientCredentialType="Basic"></transport>
    </security>
    </binding>


    Username might be unfeasible, I am sorry for my preceding declare.
    Feel free to let me know if there is anything I can help with.

    Best Regards

    Abraham

      
    • Marked as answer by Aly14 Friday, May 8, 2020 12:58 PM
    Friday, May 8, 2020 6:58 AM
    Moderator
  • Thank you so much.
    Friday, May 8, 2020 12:59 PM