2010-02-04 200 views
10

这是一个.svc IIS托管服务,具有SSL和成员资格。wcf服务无法启动

我的WCF客户报告:

System.ServiceModel.ServiceActivationException was unhandled 
    Message="The requested service, 'https://www.greenjump.nl/WebServices/OrderService.svc' could not be activated. See the server's diagnostic trace logs for more information." 
    Source="mscorlib" 

在我得到的服务器: System.ArgumentException 此集合已经包含方案http的地址。此集合中每个方案最多可以有一个地址。 参数名称:item

奇怪的是这只发生在生产服务器上,localhost开发服务器上的相同代码和配置 工作正常。 我只从更改计算机名的端点地址和 到www.webdomain.com

多个服务器跟踪

<ExceptionType> 
    System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 
</ExceptionType> 
<Message> 
    This collection already contains an address with scheme http. There can be at most one address per scheme in this collection. 
    Parameter name: item 
</Message> 
<StackTrace> 
    at System.ServiceModel.UriSchemeKeyedCollection.InsertItem(Int32 index, Uri item) 
    at System.Collections.Generic.SynchronizedCollection`1.Add(T item) 
    at System.ServiceModel.UriSchemeKeyedCollection..ctor(Uri[] addresses) 
    at System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) 
    at SharpShop.Web.StructureMap.StructureMapServiceHost..ctor(Type serviceType, Uri[] baseAddresses) 
    at SharpShop.Web.StructureMap.StructureMapServiceHostFactory.CreateServiceHost(Type serviceType, Uri[] baseAddresses) 
    at System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) 
    at System.ServiceModel.ServiceHostingEnvironment.HostingManager.CreateService(String normalizedVirtualPath) 
    at System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath) 
    at System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) 
    at System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath) 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state) 
    at System.ServiceModel.PartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state) 
    at System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state) 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke2() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.WorkItem.Invoke() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ProcessCallbacks() 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.CompletionCallback(Object state) 
    at System.ServiceModel.Channels.IOThreadScheduler.CriticalHelper.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) 
    at System.ServiceModel.Diagnostics.Utility.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) 
    at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP) 
</StackTrace> 

配置:

<system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="wsHttps"> 
      <readerQuotas maxStringContentLength="128000"/> 
      <security mode="TransportWithMessageCredential"> 
      <transport clientCredentialType="None"/> 
      <message clientCredentialType="UserName"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" > 
     <baseAddressPrefixFilters> 
     <add prefix="https://www.greenjump.nl"/> 
     </baseAddressPrefixFilters> 
    </serviceHostingEnvironment> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WsHttpWithAuthBehavior"> 
      <serviceMetadata httpsGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="true" /> 
      <serviceAuthorization principalPermissionMode="UseAspNetRoles" 
           roleProviderName="AspNetSqlRoleProvider"/> 
      <serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="MembershipProvider" 
       membershipProviderName="AspNetSqlMembershipProvider" /> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service behaviorConfiguration="WsHttpWithAuthBehavior" name="SharpShop.Services.OrderService"> 
     <endpoint address="https://www.greenjump.nl/WebServices/OrderService.svc" 
        binding="wsHttpBinding" 
        bindingConfiguration="wsHttps" 
        contract="SharpShop.Services.IOrderService"> 
      <identity> 
      <dns value="www.greenjump.nl" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" /> 
     </service> 
    </services> 
    </system.serviceModel> 
+0

我们可以看到配置? – 2010-02-04 14:00:38

+0

http://stackoverflow.com/questions/10902643/cant-activate-wcf-service/36487750#36487750 – 2016-04-07 21:49:50

+0

共享以下网址上的步骤: http://stackoverflow.com/questions/10902643/cant-activate-wcf -service/36487750#36487750 – 2016-04-07 21:50:59

回答

1

问题是由多个主机头的IIS处理造成的。 就像这里说的blowdart。 错误:该集合已经包含一个地址与方案http。

,有点用第一baseAddresses [0]是不适合我,因为我的baseAddresses在这当然为了我能做的是 http://localhost/WebServices/OrderService.svc http://www.greenjump.nl/WebServices/OrderService.svc https://vps2051.xlshosting.net/WebServices/OrderService.svc 选项更详细的在这里 http://forums.silverlight.net/forums/p/12883/274592.aspx

[1]但我不喜欢这种配置依赖。

看来我的问题是较为复杂的,由于HTTPS绑定,这是我想出了ServiceHostFactory:

public class MyServiceHostFactory : ServiceHostFactory 
    { 

     protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses) 
     { 
      Uri webServiceAddress = baseAddresses[0]; //default to first 

      if (HttpContext.Current != null) //this only works when aspNetCompatibilityEnabled=true 
      { 
       string host = HttpContext.Current.Request.Url.Host; 
       var goodAddress = baseAddresses.FirstOrDefault(a => a.Host == host);//try to find address with same hostname as request 
       if(goodAddress!=null) 
       { 
        webServiceAddress = goodAddress; 
       } 
       Type[] sslServices = { typeof(OrderService) };//add all https services here 
       if (sslServices.Any(s => s == serviceType)) 
       { 
        UriBuilder builder = new UriBuilder(webServiceAddress); 
        builder.Scheme = "https"; 
        builder.Port = 443; //fails if you use another port 
        webServiceAddress = builder.Uri; 
       } 
      } 
      return new ServiceHost(serviceType, webServiceAddress); 
     } 
    } 

不过这种感觉哈克,而且应该由微软来解决。

+0

@Medo您是否尝试将端口添加到端点和基础前缀?这是一个解决方案,所以你不需要做这个定制工厂。 – 2010-02-05 13:13:25

1

两个猜测:你有多个<端点地址=“”条目在那里。

它们可能不具有相同的值,但可能会解析为相同的名称。

或者因为它看起来像你使用的是https://,你在开发机器上使用http而在活着的机器上使用https?

如果是这样,你是否有两个单独的端点地址?理论上你不应该这么做 - 你会在http基地址上启用传输安全性,这将阻止它能够在https以外的任何地方被调用。

技术上http和https都是http方案。

+0

只有一个端点,并且在de dev机器上,我也使用https 做了一个搜索解决方案,以确保没有找到其他端点。 它在devserver中工作我只在生产 – Medo 2010-02-04 14:24:31

+0

取代域名和端点位置看着配置 - 你试过从主服务的端点删除显式的'地址='吗?如果服务将从.svc文件开始,则不需要指定基地址。 – 2010-02-05 08:29:12

0

尝试疗法的web配置添加前缀到生产服务器:

<serviceHostingEnvironment> 
    <baseAddressPrefixFilters> 
    <add prefix="https://www.greenjump.nl:443" /> 
    </baseAddressPrefixFilters> 
</serviceHostingEnvironment> 

这将被添加到<system.serviceModel>

而且你的终点应该是这样的:

<endpoint address="https://www.greenjump.nl:443/WebServices/OrderService.svc" 
       binding="wsHttpBinding" 
       bindingConfiguration="wsHttps" 
       contract="SharpShop.Services.IOrderService"> 

否则您可以像其他评论员建议的那样,始终重载ServiceFactory

8

如果您在IIS中托管,则不需要基址部分 - 因为它是IIS的站点配置,因此请移除该部分。

当为多个主机头配置IIS时存在一个“问题”,在这种情况下,您需要使用自定义工厂,该工厂将所需的所有地址除外。一个简单的例子是

namespace Example 
{ 
    public class GenericServiceHostFactory : ServiceHostFactory 
    { 
     protected override ServiceHost CreateServiceHost(Type serviceType, 
                 Uri[] baseAddresses) 
     { 
      //return the first... 
      return new ServiceHost(serviceType, baseAddresses[0]); 
     } 
    } 
} 

然后你会使用在你的.svc文件

<%@ ServiceHost 
    Service="MyImplementationClass" 
    Factory="Example.GenericServiceHostFactory" 
%> 
+0

谢谢我在那个方向工作会发布我的结果。 – Medo 2010-02-05 09:39:13

0

我可以按以下使用Visual Studio 2013的步骤来解决问题:

  1. 转到你有你* .svc文件

  2. 右击* .SVC项目文件夹文件 - >查看浏览器

  3. 验证,如果你能够浏览服务

  4. 转到您的PROJ ect文件夹,你有你的app.config文件或你想要使用服务的位置。

  5. 右键项目 - >添加 - >服务参考

  6. 点击查看 - >在服务选择服务 - >提供所需的名称为您服务的参考 - >点击OK

  7. 这将创建“ServiceReference1”的文件夹下的“服务引用” &自动创建/更新app.config文件 enter image description here