无法使用我的WebService广告连接服务

时间:2018-02-15 14:20:14

标签: c# web-services wcf

我使用基本身份验证创建了一个webService(使用this tutorial)。

有我的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>

文件夹App_Code包含文件CredentialsChecker.cs,其代码如下:

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

我创建了一个项目,我想用它来测试我的Web服务。但是当我想将服务添加为服务引用时,我收到了错误:

  

提供的URI方案“https”无效;预计'http'。

我在网络服务中遗漏了什么吗?

1 个答案:

答案 0 :(得分:1)

UsernameWithTransportCredentialOnly类型为basicHttpBinding。因此,您需要指定支持绑定的端点。将您的地址更改为http,或将绑定更改为wsHttp

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