为我配置“使用端点配置服务”演示失败(Microsoft / endpoint.tv / Pluralsight)

时间:2011-10-25 15:03:06

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

我正在尝试跟随初学者的演示视频到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>

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

6 个答案:

答案 0 :(得分:7)

我也遵循相同的webcast并遇到了同样的问题。我通过按照其他人的建议评论这些条目来解决证书问题。

我更正了“请尝试将HTTP端口更改为8732或以管理员身份运行”,方法是将“Design_Time_Addresses”添加回我的网址

不起作用

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

<强>作品!

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

答案 1 :(得分:3)

上面两个问题(HTTP could not register URL一个)的后一个看似有效的解决方案可以在Gabobcat回答评论中发表的VS2010 Training Kit中找到(由他)。

在第4个练习“Ex4-ServiceDiscovery”中,您将看到一个似乎是使用WCF服务在两个客户端之间进行通信的聊天应用程序。它使用发现功能查找网络上的对等体。简而言之,当您最初尝试运行已完成的应用程序时(在填充练习中列出的发现事件之后),会发生同样的异常。捆绑了Training Kit的是几个批处理脚本(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仅在整个项目中出现一次:

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

请告诉我这是否适合您。

答案 2 :(得分:1)

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

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

或者您在证书库中放置了一些证书。我建议在此时删除“身份”配置部分,直到您学习更多的WCF。尝试保留启动器的基本端点配置,并从您了解WCF基础知识的角度开始工作。 WCF根据您的特定需求为您提供大量(非常大)的配置选项。

也许这些链接可以帮助您更好地了解您一直在观看的视频:

希望这有帮助。

答案 3 :(得分:1)

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

答案 4 :(得分:0)

我想我会从我正在阅读的内容中添加更新的综合答案。

虽然我们都可以全力以赴地允许使用证书的权限,但大多数阅读此内容的人实际上只是希望尽快启动并运行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" />

其中任何一个似乎都是启动和运行此问题的最快方法。

答案 5 :(得分:-2)

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