2010-02-04 196 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