如何使用Windows身份验证使用wcf rest服务

时间:2017-11-29 14:43:42

标签: c# wcf web-config wcf-rest wcf-rest-contrib

我正在为WCF Rest服务使用webHttpbinding配置。

 <webHttpBinding>
        <binding name="RestBinding" closeTimeout="10:01:00" openTimeout="10:01:00" receiveTimeout="10:10:00" sendTimeout="10:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered" useDefaultWebProxy="true">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>

          </security>
        </binding>
      </webHttpBinding>

我已在下面指定了endpointBehaviors

 <extensions>
      <behaviorExtensions>
        <add name="customBehavior" type="XXX" />
      </behaviorExtensions>
    </extensions>

    <behaviors>
      <endpointBehaviors>
        <behavior name="endpointBehaviour">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <customBehavior />
        </behavior>
        <behavior name="endpointBehaviourForRestService">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
          <customBehavior/>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>

如何在IIS中托管此服务后在客户端使用此服务?

目前,我们在尝试通过

访问客户端时遇到此错误
string returnValue = webClient.UploadString("http://localhost:55107/Service1.svc/methodname", "POST", data);

错误:

System.Net.WebException occurred
  HResult=0x80131509
  Message=The remote server returned an error: (401) Unauthorized.

此外,我们无法在客户端项目中将其添加为服务引用。

请分享您的想法。

0 个答案:

没有答案