Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:48+00:00 2026-05-25T23:28:48+00:00

I’m getting this error: The communication object, System.ServiceModel.ChannelFactory`1[FxCurveService.IFxCurveService], cannot be used for communication because

  • 0

I’m getting this error:

The communication object,
System.ServiceModel.ChannelFactory`1[FxCurveService.IFxCurveService],
cannot be used for communication because it is in the Faulted state.

When I call this code:

using (var client = new WCFServiceChannelFactory<IFxCurveService>(new Uri("http://ksqcoreapp64int:5025/")))
                {
                    guid = client.Call(svc => svc.ReserveSnapshot(fxCurveKey));
                    DiscountFactorNew[] dfs = client.Call(svc => svc.GetDiscountFactors(guid, dates, from));
                    Assert.IsTrue(guid != null);
                }

It errors here – client.Call(svc => svc.ReserveSnapshot(fxCurveKey));

I have no idea why it is doing this. I am passing the right parameters, inputting the correct address for the service, what else should I be checking here?

Btw, WCFServiceChannelFactory is our own class we use to take care of making service calls. Outline here:

public class WCFServiceChannelFactory<T> : IDisposable
    {
        public WCFServiceChannelFactory();
        public WCFServiceChannelFactory(Uri uri);

        public T Channel { get; }
        public System.ServiceModel.ChannelFactory<T> ChannelFactory { get; }
        public Type ChannelType { get; }

        public void Call(Action<T> f);
        public R Call<R>(Func<T, R> f);
        public void Dispose();
    }

The thing is, the problem is not with this, as this is working in the same exact fashion in every other project but this one. Basically, I have to pass the Uri directly in mine, where as others derive it from a .config file in the project, which I was unable to do here. That’s the only difference.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:28:49+00:00Added an answer on May 25, 2026 at 11:28 pm

    You can’t access details of the exception if the channel is disposed. So the lovely using pattern construction is not recommended when accessing a WCF service. In fact, the Exception properties requires to have access to the channel to extract some information about the exception (don’t know if MS missed that point, or if there are technical reasons behind).

    I’ve written a small class to simplify the call to WCF proxies (this site helps me to understand the problem and to write the class) :

    using System;
    using System.ServiceModel;
    
    namespace Utility
    {
        public class ServiceHelper
        {
    
            /// <summary>
            /// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service 
            /// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
            /// </summary>
            /// <typeparam name="TService">The type of the service to use</typeparam>
            /// <param name="action">Lambda of the action to performwith the service</param>
            [System.Diagnostics.DebuggerStepThrough]
            public static void UsingProxy<TService>(Action<TService> action)
                where TService : ICommunicationObject, IDisposable, new()
            {
                var service = new TService();
                bool success = false;
                try
                {
                    action(service);
                    if (service.State != CommunicationState.Faulted)
                    {
                        service.Close();
                        success = true;
                    }
                }
                finally
                {
                    if (!success)
                    {
                        service.Abort();
                    }
                }
            }
            /// <summary>
            /// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service 
            /// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
            /// </summary>
            /// <typeparam name="TIServiceContract">The type of the service contract to use</typeparam>
            /// <param name="action">Action to perform with the client instance.</param>
            /// <remarks>In the configuration, an endpoint with names that maches the <typeparamref name="TIServiceContract"/> name
            /// must exists. Otherwise, use <see cref="UsingContract&lt;TIServiceContract&gt;(string endpointName, Action<TIServiceContract> action)"/>. </remarks>
            [System.Diagnostics.DebuggerStepThrough]
            public static void UsingContract<TIServiceContract>(Action<TIServiceContract> action)
            {
                UsingContract<TIServiceContract>(
                    typeof(TIServiceContract).Name,
                    action
                    );
            }
            /// <summary>
            /// WCF proxys do not clean up properly if they throw an exception. This method ensures that the service 
            /// proxy is handeled correctly. Do not call TService.Close() or TService.Abort() within the action lambda.
            /// </summary>
            /// <typeparam name="TIServiceContract">The type of the service contract to use</typeparam>
            /// <param name="action">Action to perform with the client instance.</param>
            /// <param name="endpointName">Name of the endpoint to use</param>
            [System.Diagnostics.DebuggerStepThrough]
            public static void UsingContract<TIServiceContract>(
                  string endpointName,
                  Action<TIServiceContract> action)
            {
                var cf = new ChannelFactory<TIServiceContract>(endpointName);
                var channel = cf.CreateChannel();
                var clientChannel = (IClientChannel)channel;
    
                bool success = false;
                try
                {
                    action(channel);
                    if (clientChannel.State != CommunicationState.Faulted)
                    {
                        clientChannel.Close();
                        success = true;
                    }
                }
                finally
                {
                    if (!success) clientChannel.Abort();
                }
            }
        }    
    }
    

    Then you can simply do something like this (depending if you have a service reference or the contracts :

    ServiceHelper.UsingContract<IFxCurveService>(svc=>
                {
                    guid = svc.ReserveSnapshot(fxCurveKey);
                    DiscountFactorNew[] dfs = svc.GetDiscountFactors(guid, dates, from));
                    Assert.IsTrue(guid != null);
                }),
    

    This helpers ensure the correct closing of channels, whithout disposing it. You will be able to see the actual exception then. Edit your post when you’ll find the actual exception.

    (Maybe your service factory is already using this technique. If not, do not hesitate to update it like my class).

    [edit] You still have to play with config. here is a probably working config for you :

            contract="The.Correct.Namespace.IFxCurveService"
            name="IFxCurveService" />
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.