Search code examples
c#web-serviceswcf

Unable to use my WebService ad Connected Service


I created a webService with Basic Authentication (using this tutorial).

There is my web.config :

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="UsernameWithTransportCredentialOnly">
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Basic"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>

    <behaviors>
        <serviceBehaviors>
            <behavior name="RequestUserNameConfig">
                <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
                <serviceCredentials>
                    <userNameAuthentication
                        userNamePasswordValidationMode="Custom"
                        customUserNamePasswordValidatorType="MyInterface.CredentialsChecker,App_Code.CredentialsChecker"/>
                </serviceCredentials>
            </behavior>
        </serviceBehaviors>
    </behaviors>

    <services>
        <service behaviorConfiguration="RequestUserNameConfig" name="MyInterface.MyService">
            <endpoint
                address="https://localhost:47336/MyService.svc"
                binding="basicHttpBinding"
                bindingConfiguration="UsernameWithTransportCredentialOnly"
                name="BasicEndpoint"
                contract="MyInterface.IMyService">
            </endpoint>
        </service>
    </services>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
        multipleSiteBindingsEnabled="false" />
</system.serviceModel>

A folder App_Code contains file CredentialsChecker.cs with this code :

namespace MyInterface
{
    public class CredentialsChecker : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            /* ... Some Code ... */
        }
    }
}

I created a project that I want to use to test my Web Service. But When I want to add the service as service reference, I got the error :

The provided URI scheme 'https' is invalid; expected 'http'.

Did I miss something in my web service ?


Solution

  • Your UsernameWithTransportCredentialOnly is of type basicHttpBinding. So you need to specify an endpoint that supports the binding. Either Change your address to http, or change the binding to wsHttp

              <endpoint
                    address="http://localhost:47336/MyService.svc"
                    binding="basicHttpBinding"
                    bindingConfiguration="UsernameWithTransportCredentialOnly"
                    name="BasicEndpoint"
                    contract="MyInterface.IMyService">
                </endpoint>