C# 无需窗口身份验证即可保护Wcf json web服务

C# 无需窗口身份验证即可保护Wcf json web服务,c#,json,wcf,C#,Json,Wcf,我想保护一个web服务。我必须避免窗口身份验证,因为托管公司会给我带来一些问题 怎么可能呢?对于我来说,最好的选择是在web.config文件中配置用户/密码(或者只配置密码。对于该web服务来说这就足够了) 我想我可以添加一个特殊的参数,但它看起来很难看 我的配置是: <system.serviceModel> <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBin

我想保护一个web服务。我必须避免窗口身份验证,因为托管公司会给我带来一些问题

怎么可能呢?对于我来说,最好的选择是在web.config文件中配置用户/密码(或者只配置密码。对于该web服务来说这就足够了)

我想我可以添加一个特殊的参数,但它看起来很难看

我的配置是:

  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="ct.WebServices.WsCT">
        <endpoint address="" behaviorConfiguration="ct.WebServices.Service1AspNetAjaxBehavior" binding="webHttpBinding" contract="ct.WebServices.WsCT"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ct.WebServices.Service1AspNetAjaxBehavior">
          <webHttp faultExceptionEnabled="true"/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding>
          <readerQuotas maxStringContentLength="1000000"/>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

该web服务由android设备使用

代码是:

namespace ct.WebServices
{
    [ServiceContract(Namespace = "")]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class WsCT
    {
        [OperationContract]
        [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/modif")]
        public IList<Ws.Modification> GetModifs() { return null; }
    }
}
名称空间ct.WebServices
{
[ServiceContract(名称空间=”)]
[ServiceBehavior(IncludeExceptionDetailInFaults=true)]
公共类WsCT
{
[经营合同]
[WebGet(ResponseFormat=WebMessageFormat.Json,UriTemplate=“/modif”)]
public IList GetModifs(){return null;}
}
}

我强烈建议您不要将密码存储在Web.config中……Oauth可能是一个解决方案:我希望避免将密码存储到windows 2012用户表中,因为我的系统管理员在这方面会有问题。(如需重新安装等)