none
Using WCF with custom authentication over SSL RRS feed

  • Question

  • I have implemented the above, however when I call the service with the right username and password, I get the following error:

    This is a 'System.ServiceModel.ProtocolException' that occurred in mscorlib.dll.

    This is my Web.config:

    <?xml version="1.0"?>
    <configuration>
    
      <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2"/>
      </system.web>
      <system.serviceModel>
    
        <bindings>
          <wsHttpBinding>
            <binding name="SSL">
              <security mode="TransportWithMessageCredential">
                <message clientCredentialType="UserName"/>
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        
        <services>
          <service behaviorConfiguration="CustomValidation" name="WCFService.Service1">
            <endpoint address="" binding="wsHttpBinding" contract="WCFService.IService1" bindingConfiguration="SSL"/>
            <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
          </service>
        </services>
        
        <behaviors>
          <serviceBehaviors>
            <behavior name="CustomValidation">
              <serviceMetadata httpsGetEnabled="true" />
              <serviceDebug httpsHelpPageEnabled="true" includeExceptionDetailInFaults="true" />
              <serviceCredentials>
                <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCFService.Verification, WCFService" />
              </serviceCredentials>
            </behavior>
          </serviceBehaviors>
        </behaviors>  
             
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
            To browse web app root directory during debugging, set the value below to true.
            Set to false before deployment to avoid disclosing web app folder information.
          -->
        <directoryBrowse enabled="false"/>
      </system.webServer>
    
    </configuration>
    

    This is my App.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup>
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        </startup>
        <system.serviceModel>
            <bindings>
                <wsHttpBinding>
                    <binding name="WSHttpBinding_IService1">
                        <security mode="TransportWithMessageCredential">
                            <transport clientCredentialType="None" />
                            <message clientCredentialType="UserName" />
                        </security>
                    </binding>
                </wsHttpBinding>
            </bindings>
            <client>
                <endpoint address="https://myService/Connor/WCFService/Service1.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                    contract="ServiceReference1.IService1" name="WSHttpBinding_IService1" />
            </client>
        </system.serviceModel>
    </configuration>

    Any help would be great


    Friday, April 15, 2016 12:37 PM

Answers

  • Hello,

    According to the error message, it seems that the client retrieves a html response from the web server which indicates that an error page has been served, but does not get the expected content type (text/xml; charset=utf-8) for the corresponding binding. Please try viewing the response by using the Fiddler.

    Then please type your WCF web service address in a web browser and check if it provides some more detailed error message.

    Besides, you can also try to turn on WCF tracing to see whether it can capture more detailed information at underlying channel level.

    For more information, please refer to the following similar thread:

    http://stackoverflow.com/questions/5243929/wcf-service-client-the-content-type-text-html-charset-utf-8-of-the-response-me.

    Best Regard,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, April 18, 2016 2:51 PM
    Moderator