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 3680144
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:32:31+00:00 2026-05-19T03:32:31+00:00

I have seen references on how to cast to a proxy such as: ((IContextChannel)client.InnerChannel).OperationTimeout

  • 0

I have seen references on how to cast to a proxy such as:

((IContextChannel)client.InnerChannel).OperationTimeout = new TimeSpan(0,0,240); 

to set an operationtimeout but I am using client = channelFactory.CreateChannel();

How do I cast the channel to IContextChannel? I hope this makes sense. I don’t have a complete grasp on channels in WCF.

Thanks

Alexei,

Not sure how to implement your suggestion.
In this code how would I set an operationtimeout?

        try
        {
            Binding multipleTokensBinding = MultiAuthenticationFactorBinding.CreateMultiFactorAuthenticationBinding();
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            EndpointAddress endpointaddress = new EndpointAddress(new Uri("https://justsomeservice"), EndpointIdentity.CreateDnsIdentity("someone.com"));

            ChannelFactory<TransActionSvc.TransactionPortType> channelFactory = null;
            TransActionSvc.TransactionPortType client = null;

            channelFactory = new ChannelFactory<TransActionSvc.TransactionPortType>(multipleTokensBinding, endpointaddress);
            BindingElementCollection elements = channelFactory.Endpoint.Binding.CreateBindingElements();
            elements.Find<SecurityBindingElement>().IncludeTimestamp = true;

            channelFactory.Endpoint.Binding = new CustomBinding(elements);

            channelFactory.Credentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.Root, X509FindType.FindBySerialNumber, "xxx");
            channelFactory.Credentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.Root, X509FindType.FindBySerialNumber, "xxx");

            channelFactory.Credentials.UserName.UserName = Properties.Settings.Default.UserName;
            channelFactory.Credentials.UserName.Password = Properties.Settings.Default.Password;

            TransActionSvc.fetchTranDataAsAttachmentRequest req = new WF_Prod_Svc.TransActionSvc.fetchTranDataAsAttachmentRequest();
            TransActionSvc.fetchTranDataAsAttachmentResponse res = new WF_Prod_Svc.TransActionSvc.fetchTranDataAsAttachmentResponse();
            TransActionSvc.FetchTranDataAsAttachmentRq_Type reqtype = new WF_Prod_Svc.TransActionSvc.FetchTranDataAsAttachmentRq_Type();
            TransActionSvc.FetchTranDataAsAttachmentRs_Type restype = new WF_Prod_Svc.TransActionSvc.FetchTranDataAsAttachmentRs_Type();
            TransActionSvc.EndpointReferenceType endpntref = new WF_Prod_Svc.TransActionSvc.EndpointReferenceType();

            XmlAttribute actionAttrib1 = doc.CreateAttribute("soapenv", "mustUnderstand", "http://schemas.xmlsoap.org/soap/envelope/");
            actionAttrib1.Value = "0";
            XmlAttribute actionAttrib2 = doc.CreateAttribute("xmlns");
            actionAttrib2.Value = "http://schemas.xmlsoap.org/ws/2003/03/addressing";
            XmlAttribute[] objAcctionAtrb = new XmlAttribute[2];
            objAcctionAtrb.SetValue(actionAttrib1, 0);
            objAcctionAtrb.SetValue(actionAttrib2, 1);

            TransActionSvc.AttributedURI action = new WF_Prod_Svc.TransActionSvc.AttributedURI();
            action.AnyAttr = objAcctionAtrb;
            action.Value = "Transaction";

            TransActionSvc.AttributedURI messageid = new WF_Prod_Svc.TransActionSvc.AttributedURI();
            messageid.AnyAttr = objAcctionAtrb;
            messageid.Value = System.Guid.NewGuid().ToString();

            TransActionSvc.AttributedURI to = new WF_Prod_Svc.TransActionSvc.AttributedURI();
            to.AnyAttr = objAcctionAtrb;
            to.Value = "XGI";

            TransActionSvc.EndpointReferenceType endpointreference = new WF_Prod_Svc.TransActionSvc.EndpointReferenceType();
            TransActionSvc.ReferencePropertiesType referenceproperties = new WF_Prod_Svc.TransActionSvc.ReferencePropertiesType();

            if (Svc_Division.Parsed) { reqtype.division = Svc_Division.StringValue; }
            try{reqtype.startDate = Convert.ToDateTime(Svc_StartDate.StringValue);}
            catch (FormatException ex){LogMessageToFile("Invalid Start date. " + ex.Message);}
            try{reqtype.endDate = Convert.ToDateTime(Svc_EndDate.StringValue);}
            catch (FormatException ex){LogMessageToFile("Invalid End date. " + ex.Message);}
            if (Svc_DateType.StringValue == "T")
            {
                reqtype.transactionDateType = TransActionSvc.TransactionDateType_Enum.TransactionDate;
            }
            else
            {
                reqtype.transactionDateType = TransActionSvc.TransactionDateType_Enum.PostingDate;
            }
            switch (Svc_TransType.StringValue)
            {
                case "OOP":
                    reqtype.transactionType = TransActionSvc.TransactionType_Enum.OOP;
                    break;
                case "CHARGES":
                    reqtype.transactionType = TransActionSvc.TransactionType_Enum.CHARGES;
                    break;
                default:
                    reqtype.transactionType = TransActionSvc.TransactionType_Enum.ALL;
                    break;
            }

            System.Xml.XmlElement companyid = doc.CreateElement("companyId");
            companyid.InnerText = Properties.Settings.Default.CompanyID;
            System.Xml.XmlElement[] objectarray = new System.Xml.XmlElement[1];
            objectarray.SetValue(companyid, 0);
            referenceproperties.Any = objectarray;
            endpointreference.ReferenceProperties = referenceproperties;

            req.Action = action;
            req.MessageID = messageid;
            req.To = to;
            req.ReplyTo = endpointreference;
            req.fetchTranDataAsAttachment = reqtype;

            try
            {
                client = channelFactory.CreateChannel();

                //THIS DOES NOT WORK
                client.OperationTimeout = new TimeSpan(0,10,0); 

                res = client.fetchTranDataAsAttachment(req);
                if (res.fetchTranDataAsAttachmentResponse1.WFFaultList != null)
                {
                    LogLine = string.Format("FaultCode({0});FaultType({1});FaultReason({2});Severity({3})",
                                res.fetchTranDataAsAttachmentResponse1.WFFaultList[0].faultCode,
                                res.fetchTranDataAsAttachmentResponse1.WFFaultList[0].faultType,
                                res.fetchTranDataAsAttachmentResponse1.WFFaultList[0].faultReasonText,
                                res.fetchTranDataAsAttachmentResponse1.WFFaultList[0].severity);
                }
                if (res.fetchTranDataAsAttachmentResponse1.attachment != null)
                {
                    string attachFileName = res.fetchTranDataAsAttachmentResponse1.attachment.fileName;
                    byte[] filebytes = res.fetchTranDataAsAttachmentResponse1.attachment.binaryData.Value;
                    FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "..\\..\\" + res.fetchTranDataAsAttachmentResponse1.attachment.fileName, FileMode.CreateNew, FileAccess.Write, FileShare.None);
                    fs.Write(filebytes, 0, filebytes.Length);
                    fs.Close();
                    DateTime EndReceive = DateTime.Now;
                    TimeSpan elapsed = EndReceive.Subtract(BeginReceive);
                    LogLine = string.Format("Arguments: [{0}]; FileName: {1}; FileSize: {2} bytes; ElapsedTime: {3} seconds", arguments.Trim(), attachFileName, filebytes.Length.ToString(), elapsed.TotalSeconds.ToString());
                    LogMessageToFile(LogLine);
                }
            }
            catch (CommunicationException ex1)
            {
                Abort((IChannel)client, channelFactory);
                FaultException fe = null;
                Exception tmp = ex1;
                while (tmp != null)
                {
                    fe = tmp as FaultException;
                    if (fe != null)
                    {
                        break;
                    }
                    tmp = tmp.InnerException;
                }
                if (fe != null)
                {
                    string errmsg = string.Format("The server sent back a fault: {0}", fe.CreateMessageFault().Reason.GetMatchingTranslation().Text);
                    LogMessageToFile(errmsg);
                }
                else
                {
                    string errmsg = string.Format("The request failed with exception: {0}", ex1.Message.ToString());
                    LogMessageToFile(errmsg);
                }
            }
            catch (TimeoutException)
            {
                Abort((IChannel)client, channelFactory);
                string errmsg = string.Format("The request timed out ");
                DateTime EndReceive = DateTime.Now;
                TimeSpan elapsed = EndReceive.Subtract(BeginReceive);
                LogLine = string.Format("Arguments: [{0}]; Exception: {1}; ElapsedTime: {2} seconds", arguments.Trim(), errmsg, elapsed.TotalSeconds.ToString());
                LogMessageToFile(LogLine);
            }
            catch (Exception ex)
            {
                Abort((IChannel)client, channelFactory);
                string errmsg = string.Format("The request failed with unexpected exception: {0}", ex.Message.ToString());
                LogMessageToFile(errmsg);
            }
            finally
            {
                ((IChannel)client).Close();
                channelFactory.Close();
            }
        }
  • 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-19T03:32:32+00:00Added an answer on May 19, 2026 at 3:32 am

    You will not get any usefuls (non-null/non-exception) result by casting channel factory to channel interface since there is no point for factory to implement any of channel interfaces.

    You can cast channel to some other channel interface and likely get useful result if you know what type of channel is used like in the code your refer to.

    EDIT: I think ((IContextChannel)channel).OperationTimeout = new TimeSpan(0,10,0); should work.

    Note: title of your post does not match your code…

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

Sidebar

Related Questions

I've never used nested functions, but have seen references to them in several languages
I have seen several references to people running Redis on Azure, but no implementation
I have seen the references to VistaDB over the years and with tools like
Most references I've seen, and my IDE's code completion all have my specifying a
I have seen examples of printing from a windows application but I have not
I have seen the reverse of this question quite a few times, but have
I have seen references to the showS trick to build strings (e.g., in this
I have seen many references to doing something like the following to insert a
Not looking really for a book. I have seen lots of references and links
I don't understand pointers and references very well yet, but I have a class

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.