如何消费使用Windows身份验证WCF休息服务(how to consume wcf rest s

2019-10-29 22:13发布

我使用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.

此外,我们将无法添加本作中,客户项目服务的参考。

请分享你的想法,如果任何这一点。

文章来源: how to consume wcf rest service with windows authentication