2014-09-26 104 views
0

我正在遷移服務參考以使用渠道工廠。使用渠道工廠無法調用匿名WCF服務

我將接口從服務實現分離到單獨的類庫中。

  • IIb類:IService
  • IIb類:Service
  • Web應用程序:參考IService

代碼:

配置

<bindings> 
     <basicHttpBinding> 
     <binding name="basicHttpBindingEndpoint" maxReceivedMessageSize="5242880"/> 
     </basicHttpBinding> 
    </bindings> 

類:

public class ProxyManager 
{ 
    internal static ConcurrentDictionary<string, ChannelFactory<IService>> proxies = 
        new ConcurrentDictionary<string, ChannelFactory<IService>>(); 

    internal static ChannelFactory<IService> CreateChannelFactory() 
    { 
     Global.Logger.Info("ProxyManager:CreateChannelFactory"); 
     BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 
     EndpointAddress endpointAddress = new EndpointAddress("http://domain/Service.svc"); 
     var channelFactory = new ChannelFactory<IService>(basicHttpBinding, endpointAddress); 
     return channelFactory; 
    } 

    internal static IService GetProxy(string key) 
    { 
     Global.Logger.Info("ProxyManager:GetProxy"); 
     return proxies.GetOrAdd(key, m => CreateChannelFactory()).CreateChannel(); 
    } 

    internal static bool RemoveProxy(string key) 
    { 
     Global.Logger.Info("ProxyManager:RemoveProxy"); 
     ChannelFactory<IService> proxy; 
     return proxies.TryRemove(key, out proxy); 
    } 
} 

全球:

public static IService ServiceProxy 
{ 
    get 
    { 
     return ProxyManager.GetProxy("Service"); 
    } 
} 

用法:

ServiceProxy.Method(); 

錯誤:

例外:

There was no endpoint listening at http://domain/Service.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

InnerException:The remote server returned an error: (404) Not Found.

  1. 服務是"http://domain/Service.svc"
  2. 到達該服務已啓用 「匿名」 認證和 「視窗」 驗證上IIS

禁止我在想什麼這裏?

故障排除: 1.我試着設置綁定有「BasicHttpSecurityMode.None」,這並沒有幫助。 2.嘗試設置通道工廠Windows憑據「TokenImpersonationLevel.Anonymous」,這並沒有幫助 3.嘗試讀取的EndpointAddress的IsAnonymous財產,那是假的

是否有可能在通道或通道出廠設置爲是匿名的? 是否可以將通道或通道工廠設置爲具有名稱空間?

詳細的錯誤信息:

Exception: 
Message: There was no endpoint listening at http://domain/Service.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. 
Source: mscorlib 
StackTrace: Server stack trace: 
    at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
    at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) 
    at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) 
    at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at IService.Method() 
TargetSite: Void HandleReturnMessage(System.Runtime.Remoting.Messaging.IMessage, System.Runtime.Remoting.Messaging.IMessage) 
HelpLink: 
Data: System.Collections.ListDictionaryInternal 

InnerException: 
Message: The remote server returned an error: (404) Not Found. 
Source: System 
StackTrace: at System.Net.HttpWebRequest.GetResponse() 
    at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) 
TargetSite: System.Net.WebResponse GetResponse() 
HelpLink: 
Data: System.Collections.ListDictionaryInternal 
+0

您是否試過在瀏覽器中使用「http:// domain/Service.svc」?您如何託管該服務,並在您嘗試連接時運行? – Tim 2014-09-26 18:23:25

回答

0

服務有兩個端點 - Ajax和基礎。

我沒有提到我想在ProxyManager中使用基本端點。

一旦我改變它下面的代碼段的工作:

internal static ChannelFactory<IService> CreateChannelFactory() 
    { 
     Global.Logger.Info("ProxyManager:CreateChannelFactory"); 
     BasicHttpBinding basicHttpBinding = new BasicHttpBinding(); 
     EndpointAddress endpointAddress = new EndpointAddress("http://domain/Service.svc/Basic"); 
     var channelFactory = new ChannelFactory<IService>(basicHttpBinding, endpointAddress); 
     return channelFactory; 
    } 

錯誤消息是我不明白,因爲服務的地址的工作。我應該根據錯誤消息更正端點地址。