简体   繁体   中英

“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. The communication should be duplex so I went with 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. 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:

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

IFilesDuplexCallback:

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

ClientSide 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)

[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):

// 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):

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

            selfHost = null;
        }

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(client):

<!-- 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

<security mode="None"/>

Now the connection works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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