Web Services Web服务中的方法出现拒绝访问错误

axr492tv  于 2022-11-15  发布在  其他
关注(0)|答案(2)|浏览(269)

我有一个Web服务,它在localhost上运行得很好,但是当我在测试服务器上托管它时,我在其中一个方法上遇到错误。我使用的是wsHttp绑定。除了这个方法之外,客户端上的其他一切都运行正常。这就是我遇到的错误
客户端错误:

System.ServiceModel.Security.SecurityAccessDeniedException: Access is denied.

Server stack trace: 
   at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
   at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
   at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
   at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
   at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

服务器错误:

namespace.Service Error: 10001 : Error occurred in methodname(). 
 System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.
   at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
   at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
   at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Byte[] data, Object[] values)
   at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Object[] values)
   at System.Diagnostics.EventLogTraceListener.TraceEvent(TraceEventCache eventCache, String source, TraceEventType severity, Int32 id, String format, Object[] args)
   at System.Diagnostics.TraceSource.TraceEvent(TraceEventType eventType, Int32 id, String format, Object[] args)
   at AutoWatch.Entity.WcfService.TrackingService.UpdateIncidentStatusHistory(Int64 incidentId, String status, String username, String comment, Boolean SuspectFaultyUnit) in C:\..servicename.cs:line 566
   at AutoWatch.Entity.WcfService.TrackingService.GetNewIncidentMessage(String username) in C:\..servicename.cs:line 444

失败的组件区域为:我的计算机
我添加了在服务器上遇到的错误。遇到此错误是否可能是因为服务无法写入事件日志?
请帮帮忙。

os8fio9y

os8fio9y1#

确保运行承载服务的进程的帐户具有访问数据库的权限。例如,对于IIS,运行承载服务的应用程序池的帐户必须具有登录数据库服务器的权限,并且必须具有在数据库中执行所有必要操作的权限。
编辑:
服务器堆栈追踪看起来相当简单。您在写入Windows事件记录档时发生问题!它找不到您要求的来源,而且没有建立来源的权限。

zpf6vheq

zpf6vheq2#

当我尝试在WCF服务的Web方法中使用以下语句时,出现相同的错误:

string myTypeName = typeof(ErrorHandlerBehavior).AssemblyQualifiedName;

其中ErrorHandlerBehavior是从行为延伸项目衍生而来。
当我在我的localhost上测试服务时,这行代码工作得很好。在web上,对包含方法的调用引发了异常“访问被拒绝”。
在这种情况下,我猜原因是我的IP不允许在部分信任的环境中创建BehaviourExtensionElement(我的服务在共享宿主环境中)。
最后,我成功地遵循了https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/configuring-and-extending-the-runtime-with-behaviors中描述的关于服务行为的第一个机制:
使用服务类上得属性.构造ServiceHost时,ServiceHost实现使用反射来发现服务类型上得属性集.如果这些属性中得任何一个是IServiceBehavior得实现,则将它们添加到ServiceDescription上得行为集合中.这允许这些行为参与服务运行时得构造.
我只是修改了派生(不需要其他修改):

public class ErrorServiceBehavior : Attribute, IServiceBehavior
{ ... }

并使用该类作为我的服务的属性:

[ErrorServiceBehavior()]
public partial class MyService : IMyService
{...}

无需其他修改。请检查How do I create a global exception handler for a WCF Services?处的原始样本。

相关问题