0

我正在为 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>

我在下面指定了端点行为

 <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.

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

如果对此有任何想法,请分享您的想法。

4

0 回答 0