Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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) :
HTML
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 :
C#
[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 :
C#
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
Updated 7-Oct-12 8:52am
v2
Comments
Kenneth Haugland 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 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 7-Oct-12 14:59pm    
Have you added the service reference to your project?
arashmobileboy 7-Oct-12 15:00pm    
yes i added system.servicemodel
Kenneth Haugland 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.

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...
 
Share this answer
 
Comments
arashmobileboy 7-Oct-12 15:22pm    
yes,they are in same machine,i tested with tcpbinding too but no success
The Problem Solved So Easy,

All The Problem was that i mistakenly close connection after click on button in server!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900