[英]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.