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

  • Home
  • SEARCH
  • 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 8701409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:23:32+00:00 2026-06-13T02:23:32+00:00

I am building a WCF in C#, and a client to consume it at

  • 0

I am building a WCF in C#, and a client to consume it at the same time. For some reason I am having trouble getting a method to return an int. Here is my contract:

[ServiceContract]
public interface IMData
{
  [OperationContract]
  int ReturnAnInt();

  [OperationContract]
  String HelloWorld();
}

Here is where I have implemented it:

public class MData : IMData
{
  public String HelloWorld()
  {
    return "Hello World";
  }

  public int ReturnAnInt()
  {
    return 5;
  }
}

I’m using Visual Studio, and for the client, I imported this WCF as a Web Reference. Now for some reason when I declare an instance of MData and try to call HelloWorld, there is no problem, but I get a compile error when calling ReturnAnInt.

MData m = new MData();
String helloWorld = m.HelloWorld();
int result = m.ReturnAnInt();

The error I get with ReturnAnInt is:
“No overload for method ‘ReturnAnInt’ takes 0 arguments”
So then I mouse over to see what Visual Studio is expecting, and it says that the method should look like:

void MData.ReturnAnInt(out int ReturnAnIntResult, out bool ReturnAnIntResultSpecified)

I have been banging my head against a wall over this for hours now and can find nothing on Google, and it has my coworkers baffled as well. Why did it add two out parameters that aren’t in the definition, and change the return type? Any help would be greatly appreciated. I apologize if I left out any information that would be helpful.

  • 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-13T02:23:32+00:00Added an answer on June 13, 2026 at 2:23 am

    Can you import it as a Service Reference (newer tech) instead of a Web Reference (older tech)? I work with WCF services through service references and haven’t seen such an issue – I’ve only seen a Specified property (and that as a property alongside the int, not as two out params) when the service definition allows no int to be specified (WCF-generated service definitions have, in my experience, worked as expected).

    If you can’t find a better solution, here’s a workaround using partial classes: (this would have to be done any time you return a struct, not just ints)

    public partial class MData
    {
        public int ReturnAnInt()
        {
            int result;
            bool specified;
            this.ReturnAnInt(out result, out specified);
            if (!specified) throw new InvalidOperationException();
            return result;
        }
    }
    

    Update http://www.codeproject.com/Articles/323097/WCF-ASMX-Interoperability-Removing-the-Annoying-xx has a (somewhat klunky) solution, and informs us that the root cause is that WCF generates poor (arguably inaccurate) WSDLs – they have a minOccurs="0" on elements that really don’t need it. Web References reads this as-is, and generates klunky code to deal with it, which is what you’re trying to deal with. Based on his article, you can return this type instead of an int:

    [MessageContract(IsWrapped = false)]
    public class MyInt
    {
        [MessageBodyMember]
        public int Result { get; set; }
    
        public static implicit operator MyInt(int i)
        {
            return new MyInt { Result = i };
        }
    
        public static implicit operator int(MyInt m)
        {
            return m.Result;
        }
    }
    

    Along with modifying the return type of the method:

    [ServiceContract]
    public interface IMData
    {
        [OperationContract]
        MyInt ReturnAnInt();
    
        [OperationContract]
        String HelloWorld();
    }
    public class Service1 : IMData
    {
        public MyInt ReturnAnInt()
        {
            return 4;
        }
    
        public string HelloWorld()
        {
            return "Hello World";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An exploratory question, here. After some reading, I'm getting a sinking feeling that WCF's
I am building a simple WCF service that has to return some data from
I'm building soap message which requires wse security and for some reason, the client
I'm building a WCF service,after a client connects to this service,when the service disconnect,
I'm building a WCF router and my client uses Reliable Sessions. In this scenario
I am building a WCF service now, that has a wsHttpBinding endpoint. The client
I'm about to start building an iPad client for an existing WCF service that
I've been building a WCF app behind 3 projects (contract,implementation,client) I've hosted my service
I'm building an application that uses a WCF client to retrieve data from my
Having successfully got a WCF service and client to talk to one another using

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.