简体   繁体   English

将文件字节流发送到WCF服务时,为什么会出现“ 401-未经授权”错误?

[英]Why am I getting a “401 - Unauthorized” error when sending a file byte stream to a WCF service?

I have a WCF service with a basicHttp binding hosted on II7 being called from a Silverlight client. 我有一个WCF服务,在Silverlight客户端调用的II7上托管有basicHttp绑定。 I can call all of the services on the endpoint without issue except for one. 我可以调用终结点计算机上的所有服务,除了一个服务之外没有任何问题。

I'm trying to upload a file so the service receives a byte array. 我正在尝试上传文件,以便该服务接收一个字节数组。 If I upload files over 3MB in size, I get the error below. 如果我上传的文件大小超过3MB,则会出现以下错误。

When I try calling this service: 当我尝试致电此服务时:

[OperationContract]
public AuditResponse UploadVendorAuditFile( int vendorID, 
                                            int sourceSystemID, 
                                            string fileName,
                                            byte[] fileBytes )
{
    // stuff
}

I get the following error: 我收到以下错误:

401 - Unauthorized: Access is denied due to invalid credentials. 401-未经授权:由于凭据无效,访问被拒绝。 You do not have permission to view this directory or page using the credentials that you supplied. 您无权使用您提供的凭据查看此目录或页面。

Here are my configurations. 这是我的配置。

Endpoint Binding 端点绑定

<basicHttpBinding>
  <binding 
    name="basicHttpBindingConfiguration" 
    maxBufferSize="2147483647"
    maxBufferPoolSize="2147483647" 
    maxReceivedMessageSize="2147483647"
    >
    <readerQuotas 
    maxDepth="2147483647" 
    maxStringContentLength="2147483647"
    maxArrayLength="2147483647" 
    maxBytesPerRead="2147483647" 
    maxNameTableCharCount="2147483647" 
    />
    <security mode="TransportCredentialOnly">
    <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
    </security>
  </binding>
</basicHttpBinding>

Service Configuration 服务配置

<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>
  </serviceBehaviors>
</behaviors>

Client 客户

<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding 
              name="BasicHttpBinding_WMService" 
              maxBufferSize="2147483647"
              maxReceivedMessageSize="2147483647"
              >
                <security mode="TransportCredentialOnly" />
            </binding>
        </basicHttpBinding>
    </bindings>

Are the files for which it fails are bigger in size say greater than 1MB or so? 失败的文件是否大于1MB左右? Try enabling tracing to know the actual cause of the error. 尝试启用跟踪以了解错误的实际原因。

If the files are of larger size then it might be cause of the reader quota settings which need to be set for larger values on both server and client side 如果文件较大,则可能是由于需要在服务器端和客户端将读取器配额设置设置为较大的值引起的

Also consider adding the maxItemsInObjectGraph in your serviceBehaviour as shown 还可以考虑将maxItemsInObjectGraph添加到您的serviceBehaviour中,如图所示

 <serviceBehaviors>        
    <behavior>
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>

NOTE: Make sure to have the same readerQuotas settings on both client and server side 注意:确保在客户端和服务器端具有相同的readerQuotas设置

Also try to set the below setting in your web.config 也尝试在web.config中设置以下设置

<system.web>  
     <httpRuntime maxRequestLength ="32768"/>
  </system.web>  

Make sure you are setting the max message size in your bindings on the WCF service.. 确保在WCF服务的绑定中设置最大邮件大小。

For Example: 例如:

<binding name="xxx" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
  <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="50000000" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</binding>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我会收到未经授权的Yahoo OAuth 2.0错误(401)? - Why i am getting Yahoo OAuth 2.0 error (401) Unauthorized? 为什么我在 Google Calendar API 中收到 (401) 未经授权的错误 - Why am I getting a (401) Unauthorized Error in Google Calendar API 为什么我会收到 401 未经授权的响应? - Why Am I Getting 401 Unauthorized Response? 更新WCF服务参考时出现401未经授权的错误 - 401 Unauthorized error when updating WCF service reference 在将Hammock与Tumblr API结合使用以检索喜欢项时,为什么会出现此401未经授权的错误? - Why am I getting this 401 unauthorized error while using Hammock with the Tumblr API to retrieve likes? 为什么我收到“远程服务器返回错误:(401) 未经授权”。 从这个代码片段? - Why am I getting 'The remote server returned an error: (401) Unauthorized.' from this code snippet? 将HttpResponseMessage与安全网址一起使用时,为什么会出现未经授权的401? - Why am I getting a 401 unauthorized when using HttpResponseMessage with a secure url? 尝试连接到WCF服务时为什么会出现此错误 - Why am I getting this error when trying to connect to my WCF service 使用WCF服务时出现错误 - I am getting error in consuming WCF service 从另一个WCF服务调用时,WCF Web服务IIS6 401未授权错误。 从asmx / WinForms调用可以 - WCF web service IIS6 401 unauthorized error when calling from another WCF service. Calling from asmx/WinForms is OK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM