簡體   English   中英

無法使用Channel Factory調用匿名WCF服務

[英]Anonymous WCF service not callable using Channel Factory

我正在遷移服務參考以使用渠道工廠。

我將接口從服務實現中拆分為一個單獨的類庫。

  • 類庫: IService
  • 類庫: 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();

錯誤:

例外:

http://domain/Service.svc上沒有偵聽終結點的端點可以接受該消息。 這通常是由不正確的地址或SOAP操作引起的。 有關更多詳細信息,請參見InnerException(如果存在)。

InnerException:遠程服務器返回錯誤:(404)找不到。

  1. 該服務可以在"http://domain/Service.svc"
  2. 該服務在IIS上啟用了“匿名”身份驗證,並禁用了“ Windows”身份驗證

我在這里想念什么?

故障排除: 1.我嘗試將綁定設置為沒有幫助的“ BasicHttpSecurityMode.None”。 2.嘗試將Channel Factory Windows憑據設置為“ TokenImpersonationLevel.Anonymous”,這無濟於事。3.嘗試讀取Endpointaddress的IsAnonymous屬性,並且它為false

可以將渠道或渠道工廠設置為匿名嗎? 是否可以將通道或通道工廠設置為具有名稱空間?

詳細錯誤消息:

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

服務有兩個端點-Ajax和Basic。

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

一旦我更改了下面的代碼段,它就起作用了:

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;
    }

該錯誤消息對我來說並不清晰,因為服務地址有效。 我應該已經根據錯誤消息更正了端點地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM