簡體   English   中英

wcf服務遠程服務器返回錯誤(400)錯誤的請求

[英]wcf service the remote server returned an error (400) bad request

我有一個Windows應用程序,調用WCF服務。 我在某些客戶端中收到400 Bad Request錯誤。(某些客戶端我沒有錯誤。)我增加了maxReceivedMessageSize,但是沒有用。

我增加了maxReceivedMessageSize和其他參數。

客戶端app.config:

<bindings>
  <wsHttpBinding>
    <binding name="BasicHttpBinding_IAracRandevuWS"
     closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="2000000" maxReceivedMessageSize="2000000"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
      <readerQuotas maxDepth="2000000" maxStringContentLength="2000000" maxArrayLength="2000000"
      maxBytesPerRead="2000000" maxNameTableCharCount="2000000" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
    <security mode="Message">
        <transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
        <message clientCredentialType="Windows" negotiateServiceCredential="true"
        algorithmSuite="Default" establishSecurityContext="true" />
      </security>

    </binding>
  </wsHttpBinding>
</bindings>

WCF服務app.config:

<system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="BasicHttpBinding_IAracRandevuWS"
      openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00"
      allowCookies="false" bypassProxyOnLocal="false"  maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
      messageEncoding="Text" textEncoding="utf-8"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="true"/>
        <serviceSecurityAudit auditLogLocation="Application" serviceAuthorizationAuditLevel="Failure" messageAuthenticationAuditLevel="Failure" suppressAuditFailure="true" />
  </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

客戶端如何生成配置文件? 您使用哪種方式調用服務,添加服務引用或ChannelFactory?
由於我們使用協議映射來托管服務而不使用Bindingconfiguration屬性,因此在http:// binding中不能很好地應用wshttpbinding配置。

<protocolMapping>
  <add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>

因此,默認的Clientcredential類型為Windows憑據,安全模式默認為message。
https://docs.microsoft.com/zh-cn/dotnet/framework/configure-apps/file-schema/wcf/security-of-wshttpbinding
我們需要在客戶端上顯式提供Windows憑據。

ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            client.ClientCredentials.Windows.ClientCredential.UserName = "administrator";
            client.ClientCredentials.Windows.ClientCredential.Password = "abcd1234!";

為了對此進行測試,請不要使用Fiddler,而是使用添加服務引用從控制台應用程序中的另一台計算機上調用它。
隨時讓我知道問題是否仍然存在。

這是一個網絡問題。 更新切換后,問題已解決。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM