Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF consumed as WebService adds a boolean parameter?

I've created the default WCF Service in VS2008. It's called "Service1"

public class Service1 : IService1
{
    public string GetData( int value )
    {
        return string.Format("You entered: {0}", value);
    }

    public CompositeType GetDataUsingDataContract( CompositeType composite )
    {
        if ( composite.BoolValue )
        {
            composite.StringValue += "Suffix";
        }
        return composite;
    }
}

It works fine, the interface is IService1:

[ServiceContract]
public interface IService1
{

    [OperationContract]
    string GetData( int value );

    [OperationContract]
    CompositeType GetDataUsingDataContract( CompositeType composite );

    // TODO: Add your service operations here
}

This is all by default; Visual Studio 2008 created all this.

I then created a simple Winforms app to "test" this. I added the Service Reference to my the above mentioned service and it all works. I can instanciate and call myservice1.GetData(100); and I get the result.

But I was told that this service will have to be consumed by a Winforms .NET 2.0 app via Web Services, so I proceeded to add the reference to a new Winforms .NET 2.0 application created from scratch (only one winform called form1). This time, when adding the "web reference", it added the typical "localhost" one belonging to webservices; the wizard saw the WCF Service (running on background) and added it.

When I tried to consume this, I found out that the GetData(int) method, was now GetData(int, bool).

Here's the code

    private void button1_Click( object sender, EventArgs e )
    {
        localhost.Service1 s1 = new WindowsFormsApplication2.localhost.Service1();
        Console.WriteLine(s1.GetData(100, false));
    }

Notice the false in the GetData call?

I don't know what that parameter is or where did that come from, it is called "bool valueSpecified".

Does anybody know where this is coming from? Anything else I should do to consume a WCF Service as a WebService from .NET 2.0? (winforms).

like image 467
Martin Marconcini Avatar asked Feb 10 '09 11:02

Martin Marconcini


1 Answers

Well well… apparently here's the answer and possible solutions or workarounds.

like image 115
Martin Marconcini Avatar answered Nov 09 '22 14:11

Martin Marconcini