2010-12-07 66 views
7

我試圖在同一網站內使用兩個端點一個HTTP和另一個HTTPS託管相同的服務。當爲HTTPS和HTTP託管相同的服務時,「URI的註冊已存在」

問題是我可以愉快地打電話給一個服務(無論我先打電話的第一個作品),但然後調用其他服務失敗,直到我iisreset並再次嘗試。因此,我可以愉快地一次調用兩種方法,直到一個過程回收。

我已經用盡了所有相關的Q & A和我能找到的文件,而且他們都沒有幫助我。 MSDN關於這些案例的文檔級別(這應該是不常見的)令人震驚,而且看起來沒有任何效果。

我已經使用Host/BaseAddresses/BaseAddress沒有運氣,每當我使用它,我得到另一個錯誤(無法找到HTTPS方案)。

我有一個名爲Secure的文件夾,它啓用了IIS中的HTTPS。

我已禁用mex,因此沒有允許我通過以前的錯誤的元數據。

任何人都有線索?我cluless ...

<service name="Namespace.MyService" behaviorConfiguration="MyBehaviour"> 
    <host> 
     <baseAddresses> 
     </baseAddresses> 
    </host> 
    <endpoint address="http://localhost/Services/MyService.svc/MyService" 
       name="MyService" binding="wsHttpBinding" 
       bindingConfiguration="myWsHttpBinding" contract="Namespace.IMyService" /> 

    <endpoint address="https://localhost/Services/Secure/MySslService.svc/MySslService" 
       name="MySslService" binding="basicHttpBinding" 
       bindingConfiguration="MySslServiceBinding" contract="Namespace.IMyService" /> 
    </service> 

.....

<behavior name="MyBehaviour"> 
     <custom1/> 
     <custom2/> 
     <serviceMetadata httpGetEnabled="false" /> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
     <serviceAuthorization principalPermissionMode="UseAspNetRoles" roleProviderName="CustomProvider"/> 
     <serviceCredentials> 
     <serviceCertificate findValue="Some" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /> 

     <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SomeClass, SomeDll"/> 
     </serviceCredentials> 
    </behavior> 

原來的錯誤是:

A registration already exists for URI 'http://localhost/Services/....'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: A registration already exists for URI 'http://localhost/Services/....'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InvalidOperationException: A registration already exists for URI
System.ServiceModel.Channels.UriPrefixTable 1.RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item) +320 System.ServiceModel.Channels.HttpTransportManager.Register(TransportChannelListener channelListener) +380
System.ServiceModel.Channels.TransportManager.Open(TransportChannelListener channelListener) +816
System.ServiceModel.Channels.TransportManagerContainer.Open(SelectTransportManagersCallback selectTransportManagerCallback) +121
System.ServiceModel.Channels.HttpChannelListener.OnOpen(TimeSpan timeout) +125
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
System.ServiceModel.Channels.DatagramChannelDemuxer
2.OnOuterListenerOpen(ChannelDemuxerFilter filter, IChannelListener listener, TimeSpan timeout) +606
System.ServiceModel.Channels.SingletonChannelListener`3.OnOpen(TimeSpan timeout) +91
System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) +375

這裏是WCF跟蹤日誌錯誤:

The ChannelDispatcher at 'http://localhost/Services/...' with contract(s) '"IMyService"' is unable to open its IChannelListener. System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpen(TimeSpan timeout) System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) System.ServiceModel.ServiceHostingEnvironment.HostingManager.ActivateService(String normalizedVirtualPath) System.ServiceModel.ServiceHostingEnvironment.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) System.ServiceModel.ServiceHostingEnvironment.EnsureServiceAvailableFast(String relativeVirtualPath) System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest() System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest() System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state) System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state) System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state) System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped) System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped* nativeOverlapped) System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)

回答

3

好的,我解決了我的問題。這個問題是我的印象是,我不得不在IIS中創建一個安全的文件夾,並將.svc文件放在那裏以保證SSL傳輸。事實證明,情況並非如此,我所要做的就是使用相同的.svc文件,並定義2個端點:

<endpoint address="http://localhost/Services/MyService.svc/MyService" 
      name="MyService" binding="wsHttpBinding" 
      bindingConfiguration="myWsHttpBinding" contract="Namespace.IMyService" /> 

<endpoint address="https://localhost/Services/MyService.svc/MySecureService" 
      name="MySslService" binding="basicHttpBinding" 
      bindingConfiguration="MySslServiceBinding" contract="Namespace.IMyService" /> 
1

這可能是嵌套目錄混淆IIS - 我有哈這發生在之前,儘管不在WCF上下文中。嘗試將端點地址更改爲:

address="http://localhost/MyService" 
address="https://localhost/MySslService" 

您可以嘗試從控制檯應用程序而不是IIS託管應用程序嗎?我很確定IIS會以某種方式引起你的問題,但這可能會證實它。

如果可能的話,我也會嘗試通過刪除一些配置細節來隔離問題 - 例如bindingConfiguration和behaviorConfiguration。

顯然,這些只是我將執行的調試步驟(您可能已經)嘗試並隔離問題 - 抱歉,我沒有得到完整的答案。

+0

謝謝。我明天會給它一個非嵌套結構,雖然它定義的方式有點複雜,我必須保證一個文件夾的安全,但這是可能的。 – Aliostad 2010-12-07 23:22:39

相關問題