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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:00:00+00:00 2026-05-20T13:00:00+00:00

Continuing to learn WCF, I’m trying to write a small program that would with

  • 0

Continuing to learn WCF, I’m trying to write a small program that would with a click of a button take the work from texbox1 , pass it to ServiceContract and get back its length.

Here’s how far I got.

Form1.cs:

...
wcfLib.Service myService = new wcfLib.Service();

private void button1_Click(object sender, EventArgs e)
{
    textBox2.Text = Convert.ToString( myService.go(textBox1.Text) );
}

...

and the wcf file:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace wcfLib
{

    [ServiceContract]
    public interface IfaceService
    {
        [OperationContract]
        int wordLen(string word);
    }



    public class StockService : IfaceService
    {
        public int wordLen(string word)
        {
            return word.Length;
        }
    }





    public class Service
    {
        public int go( string wordin )
        {

            ServiceHost serviceHost = new ServiceHost(typeof(StockService), new Uri("http://localhost:8000/wcfLib"));
            serviceHost.AddServiceEndpoint(typeof(IfaceService), new BasicHttpBinding(), "");

            serviceHost.Open();

            int ret = **///// HOW SHOULD I PASS wordin TO StockService to get word.Length in return?**

            serviceHost.Close();

            return ret;
        }
    }


}

what I can’t figure out right now, is how do I pass the wordin variable above into the ServiceContract?

  • 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-20T13:00:01+00:00Added an answer on May 20, 2026 at 1:00 pm

    You need to create the client in your form and call wordLen() directly… only a class that inherits from IfaceService can be called as a WCF service. So:

    //  You'll have to create references to your WCF service in the project itself...
    //  Right-click your form project and pick 'Add Service Reference', picking 
    //  'Discover', which should pick up the service from the service project... else
    //  enter http://localhost:8000/wcfLib and hit 'Go'.
    //  You'll have to enter a namespace, e.g. 'MyWcfService'... that namespace is
    //  used to refer to the generated client, as follows:
    MyWcfService.wcfLibClient client = new MyWcfService.wcfLibClient();
    
    private void button1_Click(object sender, EventArgs e) {
        // You really shouldn't have the client as a member-level variable...
        textBox2.Text = Convert.ToString(client.wordLen(textBox1.Text));
    }
    

    If your Service class is meant to host the WCF Service, it needs to be its own executable and running… put the code you have in go() in Main()

    Or host your WCF Service in IIS… much easier!

    Edit

    IIS = Internet Information Services… basically hosting the WCF Service over the web.

    To host in IIS, create a new project, “WCF Service Application”. You’ll get a web.config and a default interface and .svc file. Rename these, or add new items, WCF Service, to the project. You’ll have to read up a bit on deploying to IIS if you go that route, but for debugging in Visual Studio, this works well.

    To split into two applications, just make the form its own project… the service reference is set through the application’s config file; you just point it to the address of the machine or website, e.g. http://myintranet.mycompany.com:8000/wcflib or http://myserver:8000/wcflib.

    Thanks for the vote!

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

Sidebar

Related Questions

Continuing from my previous question , is there a comprehensive document that lists all
Continuing my problem from yesterday, the Silverlight datagrid I have from this issue is
Continuing my investigation of expressing F# ideas in C#, I wanted a pipe forward
Due to continuing crash problems, I'm about to uninstall and reinstall my copy of
I have a dl containing some input boxes that I clone with a bit
Given a table (mytable) containing a numeric field (mynum), how would one go about
I have a column containing the strings 'Operator (1)' and so on until 'Operator
I have a table containing prices for a lot of different things in a
I have two tables containing Tasks and Notes, and want to retrieve a list
I have a string containing a date, and another string containing the date format

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.