简体   繁体   中英

WCF notification service url change

I am new to WCF and I am trying to implement a push notification solution for my desktop application. I am trying to implement it using a WCF service and make use of the callback feature of WCF.

I have found this sample online which helped me a lot when creating my application. Though there is one small issue.

The sample suggests that the client should add a reference to the service. This is all fine except that I need the connection URI to be dynamic. The server could route me to a different notification URL at any given time in the application life span and the connection to the current channel needs to close and another connection should open to another server.

How can I change the sample so that the client can connect to a different service at any given time.

My suggestion is to get the URL as a parameter say strUrl then configure the endpoint in code instead of the appConfig

public void OpenConnection(string strUrl)
{
  var myBinding = new BasicHttpBinding();
  var myEndpoint = new EndpointAddress(strUrl);
  var myChannelFactory = new ChannelFactory<IMyService>(myBinding, myEndpoint);

  IMyService client = null;

  try
  {
    client = myChannelFactory.CreateChannel();
    client.MyServiceOperation();
    ((ICommunicationObject)client).Close();
  }
  catch
  {
   //...
  }
}

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