2011-10-19 38 views
8

Vấn đề này mà tôi đang gặp không xảy ra với tất cả các khách hàng đang truy cập dịch vụ của chúng tôi, nhưng điều nhất quán là khi lỗi xảy ra, nó đang xảy ra cùng một cuộc gọi dịch vụ cho một số ít khách hàng.Nhận 403 Lỗi bị cấm. Yêu cầu HTTP bị cấm với lược đồ xác thực ứng dụng khách 'Ẩn danh'

Dưới đây là các chi tiết của ngoại lệ:

System.ServiceModel.Security.MessageSecurityException The HTTP request was forbidden with client authentication scheme 'Anonymous'. System.ServiceModel.Security.MessageSecurityException: The HTTP request was forbidden with client authentication scheme 'Anonymous'. > ---> System.Net.WebException: The remote server returned an error: (403) Forbidden. at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace --- Server stack trace: at System.ServiceModel.Security.IssuanceTokenProviderBase 1.DoNegotiation(TimeSpan timeout) at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.TlsnegoTokenProvider.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout) at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout) at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout) at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.SecurityChannelFactory 1.ClientSecurityChannel 1.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout) at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout) at System.ServiceModel.Security.SecuritySessionClientSettings 1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade) at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at > Proxy.FileTransferService.IFileTransferService.EstablishProxy(DownloadRequest request) at Proxy.FileTransferService.FileTransferServiceClient. Proxy.FileTransferService.IFileTransferService.EstablishProxy(DownloadRequest request) at NormalFileTransferServiceClient.Download(Int32 packageId, IStreamWriter downloader, Archiver archiver) at LoggingFileTransferServiceClient.Download(Int32 packageId, ISt

ngoại lệ đó đã được ném bởi máy khách.

Cấu hình proxy client cho IFileTransferService là:

<binding name="WSHttpBinding_IFileTransferService" closeTimeout="00:01:00" 
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
    bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" 
    maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Mtom" 
    textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false"> 
    <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
    maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
    <reliableSession ordered="true" inactivityTimeout="00:10:00" 
    enabled="false" /> 
    <security mode="Message"> 
    <transport clientCredentialType="Windows" proxyCredentialType="None" 
     realm="" /> 
    <message clientCredentialType="UserName" negotiateServiceCredential="true" 
     algorithmSuite="Default" establishSecurityContext="true" /> 
    </security> 
</binding> 

    <endpoint address="http://[hostname]/FileTransferService.svc/FileTransfer" 
    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFileTransferService" 
    contract="Proxy.FileTransferService.IFileTransferService" 
    name="WSHttpBinding_IFileTransferService"> 
    <identity> 
     <certificate encodedValue="a long string"/> 
    </identity> 
    </endpoint> 

Cấu hình dịch vụ là

<service behaviorConfiguration="ServiceBehavior" 
    name="Services.FileTransferService"> 
     <endpoint name="WSHttpBinding_IFileTransferService" 
     binding="wsHttpBinding" 
     bindingConfiguration="MtomWSHttpBinding" 
     contract="Services.IFileTransferService" 
     address="/FileTransfer"/> 
     <endpoint binding="basicHttpBinding" 
     bindingConfiguration="FileTransferServicesBinding" 
     contract="Services.IFileTransferService"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://[hostname]/FileTransferService.svc"/> 
      </baseAddresses> 
     </host> 
</service> 

<binding name="wsHttpBinding" 
     maxReceivedMessageSize="2147483647" 
     receiveTimeout="5" 
     useDefaultWebProxy="false"> 
     <readerQuotas maxDepth="2147483647" 
      maxStringContentLength="2147483647" 
      maxArrayLength="2147483647" 
      maxBytesPerRead="2147483647" 
      maxNameTableCharCount="2147483647" /> 
    <security mode="Message"> 
    <message clientCredentialType="UserName" /> 
    </security> 
</binding> 

<basicHttpBinding> 
    <binding name="FileTransferServicesBinding" 
      maxReceivedMessageSize="10067108864" 
      messageEncoding="Mtom" 
      transferMode="Streamed" 
      useDefaultWebProxy="false"> 
     <security mode="None"> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 

Lưu ý: Một vài khách hàng đang sử dụng basicHttpBinding (nếu tôi thiết lập mọi thứ một cách chính xác). Trong bản phát hành sau của khách hàng, có thể không được phân phối đầy đủ (đó là lý do tại sao tôi phải hỗ trợ 2 phiên bản), thay vào đó tôi đã thay đổi proxy để sử dụng điểm cuối wsHttpBinding. Tôi tự hỏi nếu lỗi này mà tôi nhận được là cụ thể cho basicHttp và nếu như vậy, có lẽ tôi không có những cấu hình thiết lập đúng. Tôi theo giả định rằng các khách hàng đang nhận được lỗi này 403 đang sử dụng wsHttpBinding.

Đây là mã cho các dịch vụ:

public RemoteBinaryInfo EstablishProxy(DownloadRequest request) 
{ 
    int packageId = request.PackageId; 

    System.IO.MemoryStream stream = new System.IO.MemoryStream(packageRepository.GetPackageBinary(packageId)); 

    DisposeStreamWhenOperationIsComplete(stream, OperationContext.Current); 

    RemoteBinaryInfo result = new RemoteBinaryInfo(); 
    result.Length = stream.Length; 
    result.MemoryByteStream = stream; 
    return result; 

} 

private static void DisposeStreamWhenOperationIsComplete(System.IO.MemoryStream stream, OperationContext clientContext) 
{ 
    clientContext.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args) 
    { 
     if (stream != null) 
      stream.Dispose(); 
    }); 
} 

Có ai biết nếu điều này được thoát khỏi ngoại lệ này là một cái gì đó withing kiểm soát của tôi? Có bất kỳ thay đổi cấu hình nào mà tôi có thể thực hiện đối với tệp cấu hình ứng dụng hoặc máy khách không?

Nếu bạn cần thêm thông tin từ tôi, vui lòng cho tôi biết.

+0

Nếu chưa được thực hiện, bạn nên cố gắng vạch trần một phương thức hello world đơn giản để tách biệt vấn đề. – JoeBilly

Trả lời

0

Nghe có vẻ như tôi như khách hàng đang nhận MessageSecurityException không cung cấp tên người dùng/mật khẩu hợp lệ theo yêu cầu của họ.

Xem các chủ đề MSDN sau http://msdn.microsoft.com/en-us/library/ms733131.aspx

+0

Nếu việc trên đang được thực hiện, có sự kết nối nào giữa các máy khách đang nhận được lỗi mà tên miền mà họ đang gọi không? Cũng hữu ích khi loại trừ các khách hàng đang nhận được lỗi không gửi yêu cầu của họ thông qua proxy. Nếu không có cách nào trong số đó giúp, hãy bật tìm kiếm thư trên cả máy khách và dịch vụ: http://msdn.microsoft.com/en-us/library/ms730064.aspx –

+0

Tên người dùng và mật khẩu đang được cung cấp trực tiếp trong mã sau nó được giải mã. Không có sự tương tác của con người giữa khách hàng và các dịch vụ này. Các proxy mà tôi tạo ra được phân phối với một ứng dụng và được thực hiện tự động. – SideFX

+0

Tôi đã có creds.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerTrust; nhưng điều này có thể sửa chữa vấn đề: creds.ServiceCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine; Lỗi tôi đang nhận không xảy ra đối với mọi yêu cầu của khách hàng nhưng có thể cấu hình mạng máy khách cụ thể sẽ làm cho nó cần thiết để thêm mã ở trên. Mục đích của việc xác định vị trí của chứng chỉ máy chủ trong máy khách là gì? – SideFX

0

Vì vậy, bạn có một dịch vụ web được cấu hình trong IIS sử dụng xác thực Anonymous, và bạn nhận được một lỗi cấm 403 cho chỉ một số ít người sử dụng.

Từ kinh nghiệm của riêng tôi, điều này thường do truy cập bị từ chối ngoại lệ khi truy cập tài nguyên hệ thống được điều khiển ACL, chẳng hạn như hệ thống tệp.

Mỗi người dùng kết nối một cách bất thường sẽ yêu cầu xử lý (giả định IIS 7) bằng quy trình w3wp.exe thường có bản sắc ứng dụng (IIS APPPOOL/AppPoolName), nếu danh tính đó không được thêm vào danh sách kiểm soát truy cập bắt buộc một truy cập bị từ chối ngoại lệ sẽ gây ra IIS để trả lời với một lỗi 403.

Tôi thường thêm nhận dạng nhóm ứng dụng vào nhóm rồi thêm nhóm vào bất kỳ tài nguyên bắt buộc nào.

Nếu bạn không thể tìm ra nguồn tài nguyên nào có thể gây ra ngoại lệ, hãy thử tìm nhật ký sự kiện bảo mật cho mục nhập "Kiểm tra thất bại" cho các đầu mối. Bạn có thể cần phải cấu hình chính sách bảo mật cục bộ để ghi lại các sự kiện bảo mật.

may mắn

3

Trong trường hợp của tôi lỗi này là từ HTTP proxy server tổ chức của chúng tôi. Tìm thấy nó từ: MessageSecurityException.InnerException.Response.Headers:

{Mime-Version: 1.0
X-Squid-Lỗi: ERR_ACCESS_DENIED 0
X-Cache: Miss từ <
X-Cache-Lookup: NONE từ < proxy- server-address>
Proxy-Connection: close
Content-Length: 2165
Content-type: text/html
ngày: Wed, 25 Tháng 4 năm 2012 10:55:39 GMT
Server: squid/3.0.STABLE25
Via: 1,0 < proxy-server-address> (squid/3.0.STABLE25)
}

Trong trường hợp của tôi cũng có thể nó xảy ra cho một phương pháp chuyển tập tin đó chuyển tập tin khối trong một byte mảng kích thước 16384. Khi giảm kích thước xuống 10000, lỗi đã được giải quyết. Điều này có nghĩa là máy chủ proxy có một số loại giới hạn kích thước được đặt.

Trên một máy có truy cập internet trực tiếp, phương pháp truyền tập tin không bao giờ thất bại với lỗi này, ngay cả đối với kích thước mảng> 16384.

Vì chỉ có một số khách hàng của bạn đang phải đối mặt vấn đề này, có thể họ đang ở phía sau một tường lửa/proxy server thực sự chặn truy cập và trả lại lỗi này?

+0

Tương tự ở đây. Quên để kiểm tra Máy chủ proxy bỏ qua cho địa chỉ cục bộ – AlexDev

Các vấn đề liên quan