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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:56:38+00:00 2026-06-11T04:56:38+00:00

I want to return CookiesContainer object from WCF service but I cann’t return. I

  • 0

I want to return CookiesContainer object from WCF service but I cann’t return. I can return string from service.

Here is my Web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

 <system.web>
  <compilation debug="true" targetFramework="4.0" />
    <authentication mode="Windows">
        <forms cookieless="UseCookies" requireSSL="false" />
    </authentication>
 </system.web>

<system.serviceModel>

<services>
  <service name="WcfService1.Service1" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="" contract="WcfService1.IService1" />

    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
     <!--behavior>-->
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

<client>
  <endpoint address="http://localhost/WcfService1/Service1.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
</client>

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
      allowCookies="true" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
      maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
      messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
      useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
        maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None"
          realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>

<system.webServer>
   <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

</configuration>

Here is my
IService1.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Net;
using System.IO;
using System.Web;

namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface IService1
{
    [OperationContract]
    CookieCollection GetCookies();

    [OperationContract]
    CookieContainer GetConnect(string uname, string password);
    //string GetConnect(string uname, string password);
}
}

Here is my Service1.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Net;
using System.IO;
using System.Web;

namespace WcfService1
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
    public CookieCollection GetCookies()
    {
        HttpWebRequest req;
        CookieCollection cc = new CookieCollection();
        req = null;

        req = (HttpWebRequest)WebRequest.Create("http://site5.way2sms.com/");
        req.CookieContainer = new CookieContainer();
        // req.CookieContainer.Add(cc);

        req.CookieContainer.Add(cc);
        req.KeepAlive = true;

        req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";
        req.ContentType = "application/x-www-form-urlencoded";
        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

        req.Referer = "http://site5.way2sms.com/content/index.html";

        req.AllowAutoRedirect = true;
        req.ServicePoint.Expect100Continue = true;

        return ((HttpWebResponse)req.GetResponse()).Cookies;
    }

    public CookieContainer GetConnect(string uid, string password)
    //public string GetConnect(string uid, string password)
    {
        HttpWebRequest req;
        HttpWebResponse res;
        Stream str;


        //try
        //{
            req = (HttpWebRequest)WebRequest.Create("http://site5.way2sms.com/Login1.action");
            req.Method = "POST";
            CookieContainer con = new CookieContainer();
            req.CookieContainer = con;
            req.CookieContainer.Add(GetCookies());
            req.KeepAlive = true;

            req.UserAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";
            req.ContentType = "application/x-www-form-urlencoded";
            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

            req.Referer = "http://site5.way2sms.com/content/index.html";

            byte[] data = System.Text.Encoding.Default.GetBytes("username=" + uid + "&password=" + password);
            req.Credentials = new NetworkCredential(uid, password);
            req.ContentLength = data.Length;
            req.AllowAutoRedirect = true;
            req.ServicePoint.Expect100Continue = true;

            str = req.GetRequestStream();
            str.Write(data, 0, data.Length);
            str.Close();


            res = (HttpWebResponse)req.GetResponse();

            string iduri = System.Web.HttpUtility.ParseQueryString(res.ResponseUri.Query).Get("id");

            if (iduri != "")
            {
                return con;
                //return "Success";
            }
            else
            {
                res.Close();
                str.Close();

                return null;
                //return "Fail";
            }
        //}
        //catch (Exception ex)
        //{

        //}
    }
  }
 }

Here is my Login.xaml.cs

    private void btnSignin_Click(object sender, RoutedEventArgs e)
    {
        string uid = txtUsername.Text.Trim();
        string password = txtPassword.Password.Trim();

        networkIsAvailable = Checknetwork();
        if (networkIsAvailable)
        {
            MessageBox.Show("Network Avaliable", "Avaliable", MessageBoxButton.OK);
            //svc.GetcookiesCompleted += new EventHandler<GetcookiesCompletedEventArgs>(svc_Get_Cookies);
            //svc.GetcookiesAsync(); 

            txtblockcheck.Visibility = Visibility.Visible;
            svc.GetConnectCompleted += new EventHandler<GetConnectCompletedEventArgs>(svc_Get_Connected);
            svc.GetConnectAsync(uid, password);
        }
        else
        {
            MessageBox.Show("Please check your network", "Warning", MessageBoxButton.OK);
        }
    }


    void svc_Get_Connected(object send, GetConnectCompletedEventArgs e)
    {
        CookieContainer con = e.Result;
    }

When I return CookiesContainer from service I get this following error

There was no endpoint listening at http://localhost:3922/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

I doesn’t understand how can I return CookiesContainer Object from service to client
can anybuddy tell me ?

  • 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-06-11T04:56:39+00:00Added an answer on June 11, 2026 at 4:56 am

    If nothing else, to help debug it, I would run the serialization manually. CookieContainer is not XmlSerializable (but is Soap Serializable so that shouldn’t be the problem really) but I never like sending anything other than POCO objects that I write over webservices.

    Here is my generic serialization methods, maybe just feed it the byte array, or Convert.ToBase64String() and return that. If nothing else this will absolutely confirm that your webservice is working as expected.

    Using the methods i have below:

    public byte[] GetConnect(string uid, string password)
    {
        ...
    
        if (iduri != "")
        {
            return SerializeObject(con);
        }
    }
    

    –

    void svc_Get_Connected(object send, GetConnectCompletedEventArgs e)
    {
        CookieContainer con = DeserializeObject<CookieContainer >(e.Result);
    }
    

    –

    public static byte[] SerializeObject<T>(T obj)
    {
        try
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                BinaryFormatter xs = new BinaryFormatter();
                xs.Serialize(memoryStream, obj);
    
                return memoryStream.ToArray();
            }
        }
        catch
        {
            return null;
        }
    }
    public static T DeserializeObject<T>(byte[] xml)
    {
        BinaryFormatter xs = new BinaryFormatter();
        MemoryStream memoryStream = new MemoryStream(xml);
        return (T)xs.Deserialize(memoryStream);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to return a private field from a remoted object but i get
I want to return a json object from the onreadystatechange = function(){}, but I
I want to return a reference of an object from a vector, and the
I want to return List<ClassName> & count(int) from code-behind(C#) to javascript. How can i
I want to return the most recent ten (complete) rows from a table, but
I want to return the page id from a URL string. For example If
I want to return a set of values from function till the point they
I want to return ArrayList<HashMap<String,String>> in EL function with three String argument. How to
i want to return wchar_t frm a function. How can i implement it wchar_t
I want to return multiple rows from stored procedure in oracle.How will i do

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.