简体   繁体   English

启动WCF客户端时“找不到默认端点”

[英]“No default endpoint found” when starting WCF client

I have a Windows Service which represents the WCF-Host and a WPF-Client-Application wich represents the WCF-Client. 我有一个代表WCF主机的Windows服务,一个代表WCF客户端的WPF客户端应用程序。 The communication should be duplex so I went with WSDualHttpBinding. 通信应该是双工的,所以我选择了WSDualHttpBinding。 At first I install and start my Service which opens a WCF connection after that I start my WPF app and I get the following error (I translated it): No default endpoint was found to the contract \\ " WCFCloudManagerFolderWatcherService.Interfaces.IFilesDuplex \\ " in the service model client configuration section refers. 最初,我安装并启动我的服务,该服务会在打开WCF应用程序后打开WCF连接,并收到以下错误(我将其翻译):在以下目录中找不到默认端点\\ WCFCloudManagerFolderWatcherService.Interfaces.IFilesDuplex \\服务模型客户端配置部分参考。 This may be caused by: For the purposes of no configuration file was found or in the client element no endpoint element was found , which corresponded to this contract . 这可能是由于:出于未找到配置文件或在客户端元素中未找到与该合同相对应的终结点元素的目的。

Contracts: IFilesDuplex-Contract: 合同:IFilesDuplex合同:

[ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples", SessionMode = SessionMode.Required,
            CallbackContract = typeof(IFilesDuplexCallback))]
public interface IFilesDuplex
{
    [OperationContract(IsOneWay = true)]
    void Update();
}

IFilesDuplexCallback: IFilesDuplexCallback:

interface IFilesDuplexCallback
{
    [OperationContract(IsOneWay = true)]
    void Equals(string[] result);
}

ClientSide CallbackHandler: 客户端 CallbackHandler:

class CallbackHandler : IFilesDuplexCallback
{
    public event Action<string[]> ReceivedList = delegate { };

    public void Equals(string[] result)
    {
        this.ReceivedList(result);
    }
}

The Client itself: 客户本身:

class FilesDuplexClient : DuplexClientBase<IFilesDuplex>, IFilesDuplex
{
    public FilesDuplexClient(InstanceContext callbackCntx)
        : base(callbackCntx)
    {            
    }

    public void Update()
    {
        base.Channel.Update();
    }
}

And the Code from the Main Window, where the error is thrown: 以及从主窗口中抛出错误的代码:

CallbackHandler ch = new CallbackHandler();
        ch.ReceivedList += ch_ReceivedList;

        // Construct InstanceContext to handle messages on callback interface
        InstanceContext instanceContext = new InstanceContext(ch);

        // Create a client
        FilesDuplexClient client = new FilesDuplexClient(instanceContext);
        client.Update();

Serverside (Windows Service) FileProtocoll-Class (Server code) 服务器端(Windows服务) FileProtocoll-Class(服务器代码)

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
public class FileProtocoll : IFilesDuplex
{
    IFilesDuplexCallback Callback
    { get { return OperationContext.Current.GetCallbackChannel<IFilesDuplexCallback>(); } }

    void IFilesDuplex.Update()
    {
        //....
        Callback.Equals(null);// just a dummy
        //...
    }

}

Code in the OnStart-Method (in a Thread): OnStart-Method中的代码(在线程中):

// Step 1 Create a URI to serve as the base address.
        Uri baseAddress = new Uri("http://localhost:8899/CloudManager/CommunicationChannel1");

        // Step 2 Create a ServiceHost instance
        if (selfHost != null)
        {
            selfHost.Close();
        }

        selfHost = new ServiceHost(typeof(FileProtocoll), baseAddress);

        try
        {
            // Step 5 Start the service.
            selfHost.Open();



        }
        catch (CommunicationException ce)
        {
             selfHost.Abort();
        }

Code in the OnStop-Method (in a Thread): OnStop方法中的代码(在线程中):

if (selfHost != null)
        {
            if (selfHost.State != CommunicationState.Closed)
            { 
                selfHost.Close();
            }

            selfHost = null;
        }

App.config: App.config中:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>     
    </startup>
  <system.serviceModel>
    <services >
      <service behaviorConfiguration="ServiceBehavior"
   name="WCFCloudManagerFolderWatcherService.Communication.FileProtocoll">
        <endpoint address="http://localhost:8899/CloudManager /CommunicationChannel1"
        binding="wsDualHttpBinding"     contract="WCFCloudManagerFolderWatcherService.Interfaces.IFilesDuplex">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex"
        binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true "/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

I finally got it. 我终于明白了。 Had to make a few changes to my Client app.config and had to turn off security. 必须对我的客户端app.config进行一些更改,并且必须关闭安全性。

app.config(client): app.config(客户端):

<!-- WCF Client information-->
<system.serviceModel>
<bindings>
  <wsDualHttpBinding>
    <binding name="WSDualHttpBinding_IFilesDuplex">
      <security mode="None"/>
    </binding>
  </wsDualHttpBinding>
</bindings>
<client>
  <endpoint
    address="http://localhost:8899/CloudManager/CommunicationChannel1"
    binding="wsDualHttpBinding"
    bindingConfiguration="WSDualHttpBinding_IFilesDuplex"
        contract="WCFCloudManagerFolderWatcherService.Interfaces.IFilesDuplex"
    name="WSDualHttpBinding_IFilesDuplex">
    <identity>
      <userPrincipalName value="localhost"/>
    </identity>
  </endpoint>
</client>

and in the app.config for the serverside I also hat to set 在服务器端的app.config中,我也可以设置

<security mode="None"/>

Now the connection works. 现在连接正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM