Solved

C# WCF proxy Help me understand this example code...

Posted on 2008-06-23
5
1,840 Views
Last Modified: 2013-12-16
I am trying to use this class for calling my WCF Service


http://electroholic.com/?p=10

in the sample the author has this code
ExampleWCFClient client = proxy = new ExampleWCFClient();

this will not compile.


using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Text;

using System.ServiceModel;
 

namespace ConsoleApplication1

{

    public delegate void SafeProxyInvocationHandler(out ICommunicationObject proxy);
 

    public static class SafeProxyHandler

    {

        public static Exception Invoke(SafeProxyInvocationHandler del)

        {

            return Invoke(null, del);

        }
 

        public static Exception Invoke(string messageTemplate,

                                        SafeProxyInvocationHandler del)

        {

            if (del == null)

                throw new ArgumentException("Expected delegate instance for handler to invoke!");
 

            ICommunicationObject proxy = null;
 

            try

            {

                del(out proxy);

                HandleClose(proxy);
 

                return null;

            }

            catch (TimeoutException exception)

            {

                HandleException(proxy, exception, messageTemplate);

                return exception;

            }

            catch (FaultException exception)

            {

                HandleException(proxy, exception, messageTemplate);

                return exception;

            }

            catch (CommunicationException exception)

            {

                HandleException(proxy, exception, messageTemplate);

                return exception;

            }

            catch (Exception exception)

            {

                HandleException(proxy, exception, messageTemplate);

                return exception;

            }

        }
 

        private static void HandleClose(ICommunicationObject proxy)

        {

            if (proxy != null

                && proxy.State != CommunicationState.Closed

                && proxy.State != CommunicationState.Closing

                && proxy.State != CommunicationState.Faulted)

                proxy.Close();

        }
 

        private static void HandleException(ICommunicationObject proxy,

                                                          Exception e,

                                                          string messageTemplate)

        {

            AbortClient(proxy);

            ReportException(e, messageTemplate);

        }
 

        private static void ReportException(Exception e, string template)

        {

            Trace.WriteLine(FormatMessage(template, e.GetType().Name));

        }
 

        private static string FormatMessage(string message, params string[] args)

        {

            return args == null || args.Length == 0 ? message : string.Format(message, args);

        }
 

        private static void AbortClient(ICommunicationObject proxy)

        {

            if (proxy != null)

                proxy.Abort();

        }

    }

}

Open in new window

0
Comment
Question by:JonMny
  • 2
5 Comments
 
LVL 16

Expert Comment

by:ororiole
Comment Utility
What error are you getting? And post the code where you used it so we can take a look at the problem.
0
 
LVL 9

Accepted Solution

by:
JonMny earned 0 total points
Comment Utility
ExampleWCFClient client = proxy = new ExampleWCFClient();


I fixed the problem, needed to cast the wcf
0
 
LVL 16

Expert Comment

by:ororiole
Comment Utility
I did request of the asker to post the code where he was using that line. As It is not in the first post. And post the error he was getting. Since I added value to the question, and several days elapsed, I'm confident that at least partial value should be awarded.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now