Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WCF
I used this link to learn WCF programming
 
I used the sample code in that link that was for connection between client and server. Now I want to convert that console applications to WPF but I get this error when I run client (of course I run server before running client) :
There was no endpoint listening at net.pipe://localhost/PipeReverse that could accept the message. This is often caused by an incorrect address or SOAP action.
Also I should say that sample code does not have any app.config file.
 
In MainWindow.xaml file for client :
[CallbackBehavior( ConcurrencyMode=ConcurrencyMode.Multiple,UseSynchronizationContext=false )]
public partial class MainWindow : Window,ICallbacks
{
    public void MyCallbackFunction(string callbackValue)
    {
        Dispatcher dispatcher=Dispatcher.CurrentDispatcher;
        dispatcher.BeginInvoke( new Action(
        () => textBox1.Text = callbackValue ) );
        //     MessageBox.Show( "Callback Received: {0}",callbackValue );
    }
    IStringReverser _channel;
    [ServiceContract( SessionMode = SessionMode.Required,
    CallbackContract = typeof( ICallbacks ) )]
    public interface IStringReverser
    {
        [OperationContract]
        string ReverseString(string value);
    }
 

    public MainWindow()
    {
        InitializeComponent();
        MainWindow myCallbacks = this;
        var pipeFactory = new DuplexChannelFactory<IStringReverser>(
           myCallbacks,
           new NetNamedPipeBinding(),
           new EndpointAddress(
              "net.pipe://localhost/PipeReverse" ) );
        ThreadPool.QueueUserWorkItem( new WaitCallback(
            (obj) =>
            {
                _channel = pipeFactory.CreateChannel();
            } ) );
    }
 
    private void button1_Click(object sender,RoutedEventArgs e)
    {
      _channel.ReverseString( "Hello World" );
    }
}
public interface ICallbacks
{
    [OperationContract( IsOneWay = true )]
    void MyCallbackFunction(string callbackValue);
}
In MainWindow.xaml file for server :
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }
 

    private void button1_Click(object sender,RoutedEventArgs e)
    {
        using (ServiceHost host = new ServiceHost(
       typeof( StringReverser ),
        new Uri[]{
      new Uri("net.pipe://localhost")
        } ))
        {
            host.AddServiceEndpoint( typeof( IStringReverser ),
              new NetNamedPipeBinding(),
              "PipeReverse" );
 
            host.Open();
 
            MessageBox.Show( Properties.Resources.Service_is_available__Press__ENTER__to_exit_ );
            host.Close();
        }
    }
}
 
[ServiceContract(SessionMode = SessionMode.Required,
                 CallbackContract = typeof( ICallbacks ) )]
public interface IStringReverser
{
    [OperationContract]
    string ReverseString(string value);
}
 
public interface ICallbacks
{
    [OperationContract( IsOneWay = true )]
    void MyCallbackFunction(string callbackValue);
}
 
public class StringReverser : IStringReverser
{
    public string ReverseString(string value)
    {
        char[] retVal = value.ToCharArray();
        int idx = 0;
        for (int i = value.Length - 1;i >= 0;i--)
            retVal[idx++] = value[i];
 
        ICallbacks callbacks =
     OperationContext.Current.GetCallbackChannel<ICallbacks>();
 
        callbacks.MyCallbackFunction( new string( retVal ) );
 
        return new string( retVal );
    }
}
Posted 7-Oct-12 8:50am
Edited 7-Oct-12 8:52am
v2
Comments
Kenneth Haugland at 7-Oct-12 14:53pm
   
Looks like your SVC server isn't running, but I don't know. I also assume that this is for debug testing since you use localhost.
arashmobileboy at 7-Oct-12 14:56pm
   
i successfully ran the server and client of that console application,now do you think the svc server is not running?yes it is for testing now,i am just trying to learn duplex connection with wcf
Kenneth Haugland at 7-Oct-12 14:59pm
   
Have you added the service reference to your project?
arashmobileboy at 7-Oct-12 15:00pm
   
yes i added system.servicemodel
Kenneth Haugland at 7-Oct-12 15:05pm
   
I think you should take a look at this search from google and find out what you have done differently:
https://www.google.no/search?q=using+WCF+in+WPF&aq=f&oq=using+WCF+in+WPF&sugexp=chrome,mod=3&sourceid=chrome&ie=UTF-8
You could have done a lot of things the wrong way, and I can't tell what you are missing.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

R both server and client in same machine? net.pipe works only if server and client are the same machine...you can try with basicHttpbindig to check if you can consume the service from client...
  Permalink  
Comments
arashmobileboy at 7-Oct-12 15:22pm
   
yes,they are in same machine,i tested with tcpbinding too but no success
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The Problem Solved So Easy,
 
All The Problem was that i mistakenly close connection after click on button in server!
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 339
1 _Amy 310
2 Nirav Prabtani 268
3 Sergey Alexandrovich Kryukov 216
4 CHill60 170
0 OriginalGriff 7,889
1 Sergey Alexandrovich Kryukov 7,006
2 Maciej Los 4,014
3 Peter Leow 3,708
4 CHill60 2,762


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 7 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100