【问题标题】:"Configuring Services with Endpoints" Demo Fails For Me (Microsoft/endpoint.tv/Pluralsight)“使用端点配置服务”演示对我来说失败了 (Microsoft/endpoint.tv/Pluralsight)
【发布时间】:2011-12-15 00:53:30
【问题描述】:

我正在尝试关注 MSDN 上 WCF 页面上的初学者演示视频。

第一个视频效果差不多。我现在接近第二个视频的结尾。我使用的是 VS2010 / .NET 4.0,而视频似乎使用的是 VS2008(我假设是 .NET 3.5,但我不记得了)。

I'm using the following demo

我们刚刚添加了另外 3 个端点:一个普通的 http、net.tcp 和 net.pipe。当我现在尝试运行该项目时,Web 服务无法启动。

System.InvalidOperationException: Cannot load the X.509 certificate identity specified in the configuration.
   at System.ServiceModel.Description.ConfigLoader.LoadIdentity(IdentityElement element)
   at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host, ServiceDescription description, ServiceElement serviceElement, Action`1 addBaseAddress)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, ServiceElement serviceSection)
   at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader, ServiceDescription description, String configurationName)
   at System.ServiceModel.ServiceHostBase.ApplyConfiguration()
   at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost.InitializeDescription(Type serviceType, UriSchemeKeyedCollection baseAddresses)
   at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, ServiceKind kind)
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)

根据我的 Google fu,我遇到了这个帖子:"Cannot load the X.509 certificate identity specified in the configuration"

我真的不想参与证书,因为我仍然只是在尝试基础知识,所以我按照那篇文章中的建议添加了<dns value="localhost" /> 标签。异常变化:

Please try changing the HTTP port to 8732 or running as Administrator.
System.ServiceModel.AddressAccessDeniedException: HTTP could not register URL http://+:8080/EvalService/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details). ---> System.Net.HttpListenerException: Access is denied
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   --- End of inner exception stack trace ---
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()
   at System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener)
   at System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback)
   at System.ServiceModel.Channels.TransportChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.DatagramChannelDemuxer`2.OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout)
   at System.ServiceModel.Channels.SingletonChannelListener`3.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.NegotiationTokenAuthenticator`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityUtils.OpenCommunicationObject(ICommunicationObject obj, TimeSpan timeout)
   at System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequired(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout)
   at System.ServiceModel.Security.SecurityProtocolFactory.Open(String propertyName, Boolean requiredForForwardDirection, SecurityTokenAuthenticator authenticator, TimeSpan timeout)
   at System.ServiceModel.Security.SymmetricSecurityProtocolFactory.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityProtocolFactory.Open(Boolean actAsInitiator, TimeSpan timeout)
   at System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionSecurityTokenAuthenticator.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.CommunicationObjectSecurityTokenAuthenticator.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityUtils.OpenCommunicationObject(ICommunicationObject obj, TimeSpan timeout)
   at System.ServiceModel.Security.SecurityUtils.OpenTokenAuthenticatorIfRequired(SecurityTokenAuthenticator tokenAuthenticator, TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionServerSettings.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecuritySessionServerSettings.Open(TimeSpan timeout)
   at System.ServiceModel.Security.SecurityListenerSettingsLifetimeManager.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.SecurityChannelListener`1.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
   at System.ServiceModel.Channels.CommunicationObject.Open()
   at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
System.Net.HttpListenerException (0x80004005): Access is denied
   at System.Net.HttpListener.AddAllPrefixes()
   at System.Net.HttpListener.Start()
   at System.ServiceModel.Channels.SharedHttpTransportManager.OnOpen()

所以,我尝试按照它所说的去做:将端口更改为 8732,但仍然抛出异常,这次是 Please try changing the HTTP port to 8732...HTTP could not register URL http://+:8732/EvalService/...。 :P

我尝试注释掉新的端点无济于事。即使是原始的也因此错误而失败。如果我把它们放回原来的端口 [不是这样] 1337 也没关系。

这是 App.config,没有任何问题:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="EvalServiceLibrary.EvalService">
        <clear />
        <endpoint address="ws" binding="wsHttpBinding" contract="EvalServiceLibrary.IEvalService"
          listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
          listenUriMode="Explicit">
          <identity>
              <dns value="localhost" />
              <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="basic" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService"
          listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="net.tcp://localhost:8888/EvalService" binding="netTcpBinding"
          contract="EvalServiceLibrary.IEvalService" listenUriMode="Explicit">
          <identity>
            <dns value="localhost" />
            <certificateReference storeName="My" storeLocation="LocalMachine"
              x509FindType="FindBySubjectDistinguishedName" />
          </identity>
        </endpoint>
        <endpoint address="net.pipe://localhost/EvalService" binding="netNamedPipeBinding"
          bindingConfiguration="" contract="EvalServiceLibrary.IEvalService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/EvalService" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

出了什么问题/我该如何解决?

【问题讨论】:

    标签: wcf exception-handling x509 wcf-configuration wcf-endpoint


    【解决方案1】:

    我也遵循了相同的webcast 并遇到了同样的问题。我按照其他人的建议将这些条目注释掉,从而解决了证书问题。

    我通过将“Design_Time_Addresses”添加回我的 url 更正了“请尝试将 HTTP 端口更改为 8732 或以管理员身份运行”

    不起作用

    <add baseAddress="http://localhost:8732/AMessageService" />
    

    有效!

    <add baseAddress="http://localhost:8732/Design_Time_Addresses/AMessageService" />
    

    【讨论】:

    • 在 VS 2012 中也适用于我。
    【解决方案2】:

    对于上述两个问题中的后者(HTTP could not register URL 之一),可以在 Gabobcat 的答案(由他)的 cmets 中发布的 VS2010 Training Kit 中找到看似可行的解决方案。

    在第 4 个练习“Ex4-ServiceDiscovery”中,您将看到一个使用 WCF 服务在两个客户端之间进行通信的聊天应用程序。它使用发现功能来查找网络上的对等点。长话短说,当您最初尝试运行已完成的应用程序时(在填写练习中列出的发现事件之后)时,会发生相同的异常。与培训工具包捆绑在一起的是几个批处理脚本(AFAICT 使用 Microsoft 的“开源”许可证,因此我应该能够共享这些脚本)来设置或删除“URL ACL”。实际上,它们似乎只是一个(有用的)命令:

    文件:AddURLACL.cmd

    @Echo Off
    @Echo Grant permissions for URL reservation
    @Echo Parameter 1 "%1" == port
    @Echo Parameter 2 "%2" == URL
    pause
    netsh http add urlacl url=http://+:%1/%2 user=%USERDOMAIN%\%USERNAME%
    

    文件:DelURLACL.cmd

    @Echo Off
    @Echo Deletes permissions for URL reservation
    @Echo Parameter 1 "%1" == port
    @Echo Parameter 2 "%2" == URL
    pause
    netsh http delete urlacl url=http://+:%1/%2
    

    显然,netsh 命令是唯一重要的命令。示例项目让您使用以下命令(从“以管理员身份运行”命令提示符窗口)“修复”此异常:

    C:\VS2010TrainingKit\Labs\WhatsNewInWCF4\Source\Setup\AddURLACL.cmd 8000
    

    (我使用绝对路径只是为了向您展示在培训工具包中可以找到这些脚本的位置;我个人在执行此操作时位于 WhatsNewInWCF4\Source 目录中)

    字符串 8000 在整个项目中仅出现 1 次:

    C:\VS2010TrainingKit\Labs\WhatsNewInWCF4\Source\Ex4-ServiceDiscovery\Begin\C#>findstr /n /s "8000" *
    DiscoveryChat\SimpleChat.cs:376:            this.localAddress = new Uri("http://localhost:8000/" + Guid.NewGuid().ToString());
    

    似乎端口 8000 是聊天客户端尝试启动服务主机的端口(不要问我他们是如何共享它的...我假设他们使用的 ServiceHost 类足够智能重用现有服务...)。

    我还没有对此进行彻底的试验,但它似乎已经“修复”了我的 EvalService 项目(当我将端口更改为 8000 时)。目前大多数端点已被移除(只剩下basicHttpBinding 端点),baseAddress 设置为localhost:8000

    让我知道这是否也适合你。

    【讨论】:

      【解决方案3】:

      我对同样的问题感到沮丧。最后,我通过右键单击 Visual Studio 2010 并选择“以管理员身份运行”以管理员身份运行 Visual Studio,自己找到了解决方案。

      【讨论】:

        【解决方案4】:

        问题出在您的配置中。您正在引用端点中的证书。要么删除它们:

        <certificateReference storeName="My" storeLocation="LocalMachine" x509FindType="FindBySubjectDistinguishedName" />
        

        或者您将一些证书放在证书存储中。我建议此时删除“身份”配置部分,直到您了解更多关于 WCF 的信息。尝试只停留在初学者的基本端点配置上,并从您了解 WCF 基础知识的角度开始工作。 WCF 会根据您的特定需求为您提供大量(非常大)的配置选项。

        也许这些链接比您一直在观看的视频更能帮助您进入 WCF:

        希望这会有所帮助。

        【讨论】:

        • 谢谢。注释掉 &lt;identity&gt; 标签可以消除 X.509 证书错误,但我仍然会遇到绑定错误。我认为 &lt;identity&gt; 部分也是由 Visual Studio 自动添加的(我没有任何特殊操作),因此在此演示中必须摆脱它们似乎不直观。
        • 你有多少个 Enpoint/Bindings?从一个带有 basicHttpBinding 的端点开始。删除其他端点及其引用的绑定。您使用的是 VS 开发服务器还是其他 Web 服务器?如果是这样,让 VS 控制端口号。如果您使用的是其他 Web 服务器,为了您的演示,请坚持使用端口 80。如果需要,请发布您收到的新例外情况。
        • 上面发布的第一个链接是OP中的第一个链接。 ;) 那是我找到视频的地方。 :P
        • 如果我注释掉所有其他端点(包括 mex)并只留下&lt;basicHttpBinding&gt;(注释掉&lt;identity&gt;),然后将&lt;baseAddress&gt; 更改为http://localhost/EvalService,我仍然从 OP 获得后一个异常:访问被拒绝,不拥有命名空间的权限等...
        • 我昨天无法发布的最后一件事。下载VS2010TrainingKit。它包含分步教程、教程的开始和结束代码示例,因此您可以将结果与预期结果进行比较,它涵盖了 VS2010 和 .NET 的许多方面,而不仅仅是 WCF。不要对视频教程感到沮丧。它是基本的,但它使用了一些无法帮助您理解 WCF 的工具,并且使事情变得更加晦涩难懂。一开始从来都不是一件容易的事,但坚持下去,你就会得到它。希望这可以帮助。祝你好运。
        【解决方案5】:

        我想我会根据我正在阅读的内容添加一个更新的综合答案。

        虽然我们都可以竭尽全力为证书授予权限,但大多数阅读本文的人实际上只是想尽快启动并运行 WCF 端点。

        因此有几个选择。

        1. sudipto-kumar-mukherjee above states "I was frustated with the same issue. 
        Finally I found the solution by myself by running the Visual Studio as Administrator 
        by right clicking Visual Studio 2010 and choosing 'Run As Administrator'."   
        --> Yes,  this     will work.
        OR
        2. nasp.tech response with 
        "Doesn't Work"
        <add baseAddress="http://localhost:8732/AMessageService" />
        "Works!"
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/AMessageService" />
        

        这两种方法似乎都是解决此问题的最快方法。

        【讨论】:

          【解决方案6】:

          要以管理员身份运行,请右键单击 Visual Studio,然后从上下文菜单中选择以管理员身份运行。 要始终以管理员身份运行,请右键单击 Visual Studio,然后转到上下文菜单中的属性 转到兼容性选项卡,然后选择以管理员身份运行此程序。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2022-01-02
            • 2019-08-12
            • 1970-01-01
            • 1970-01-01
            • 2011-04-22
            • 1970-01-01
            • 1970-01-01
            • 2013-06-03
            相关资源
            最近更新 更多