【问题标题】:WCF Access DeniedWCF 访问被拒绝
【发布时间】:2012-07-10 09:19:13
【问题描述】:

我有一台本地化 WCF 服务的 PC,我可以在 C# 程序中添加对该服务的引用。但是,当我运行该程序时,我收到拒绝访问错误。除了拒绝访问之外,我没有得到任何其他信息。

有没有人对如何做有任何建议。我有另一台机器,它的设置看起来相同,但能够连接到同一台机器上的本地化版本。我查看了其他已发布的问题,但似乎没有任何问题。

已编辑....

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.diagnostics> 
       <sources> 
            <source name="System.IdentityModel" switchValue="All"> 
                <listeners> 
                    <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
                        <filter type="" /> 
                    </add> 
                    <add name="IdentityModelListener"> 
                        <filter type="" /> 
                    </add> 
                </listeners> 
            </source> 
        </sources> 
        <sharedListeners> 
            <add initializeData="C:\Tracing\App_identitymodellog.svclog"                    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
         name="IdentityModelListener" traceOutputOptions="Timestamp, Callstack">
            <filter type="" /> 
        </add> 
    </sharedListeners> 
    <trace autoflush="true" /> 
</system.diagnostics> 
    <system.web>
<compilation debug="true" targetFramework="4.0">
        <assemblies></assemblies></compilation>
        <identity impersonate="true" userName="domain\username" password="password" />
    <hostingEnvironment shadowCopyBinAssemblies="false"/>
<trust level="Full" /> 
</system.web>
<system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <behaviors>
        <serviceBehaviors>
            <behavior>
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

app.config 是:-

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://localhost:2745/ActDemo/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
    contract="ActWS.IService" name="BasicHttpBinding_IService" />
  <endpoint address="http://localhost/ActDemo/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
    contract="Act.IService" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>`

代码:-

using ActDemoApp;    

namespace ActDemoApp
{
    class Program
    {
        static void Main(string[] args)
        {


            string strXML="";
            string strRetXML = "";

            try
            {

                ActWS.IService oService;

                ActWS.Request oRequest = new ActWS.Request();
                ActWS.Response oResponse;

                ActWS.Acceptance oAccept = new ActWS.Acceptance();


                StreamReader streamReader = new StreamReader("c:\\temp\\Request.dat");
                strXML = streamReader.ReadToEnd();
                streamReader.Close();

                Stopwatch stopWatch = new Stopwatch();
                oRequest = new ActWS.Request();
                oService = new ActWS.ServiceClient("BasicHttpBinding_IService1");

                // To ignore BindingFailure, turn off Errors -> Managed Debugging Assitant -> BindingFailure


                oResponse = new ActWS.Response();

                strRetXML  = oService.MakeRequest(strXML);

                if (strRetXML == null)
                {
                    Console.WriteLine("XML was invalid");
                    Environment.Exit(0);
                }

【问题讨论】:

  • 您至少应该发布您的客户端和服务器配置(来自 .config 文件或代码,具体取决于您使用的内容)。
  • 检查您的代码的代码访问策略。似乎您的代码部分受信任。
  • 根据要求,我已经更新了我的原始评论以包含配置文件。你有关于我需要做什么 Shailesh 的链接吗?用户详细信息在服务器上是正确的,只是在这里匿名。
  • 谁说“拒绝访问”?启动应用时是 .NET 运行时,是 IIS 拒绝访问服务,在哪一行代码发生?
  • 异常中的消息,只是说“拒绝访问”。当我调用 MakeRequest 时发生错误。

标签: wcf


【解决方案1】:

发现问题出在哪里,很可笑。虽然我认为这是 IIS 或 .NET 的原因,但我和问题一样接近问题。问题是 Windows 防火墙被设置为阻止包括网络流量在内的所有内容。问题发布在这里是因为我认为它是 .NET 代码。

感谢 Grzegorz、CodeCaster 和 Shailesh 花时间阅读并提供建议。

【讨论】:

    猜你喜欢
    • 2012-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-10
    • 2021-03-06
    • 2011-05-15
    • 2010-09-06
    相关资源
    最近更新 更多