WebService添加布尔参数时消耗的WCF?

我在VS2008中创建了默认的WCF服务。 它被称为“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; } } 

它工作正常,接口是IService1:

 [ServiceContract] public interface IService1 { [OperationContract] string GetData( int value ); [OperationContract] CompositeType GetDataUsingDataContract( CompositeType composite ); // TODO: Add your service operations here } 

这是默认情况下的全部; Visual Studio 2008创建了所有这些。

然后我创建了一个简单的Winforms应用程序来“测试”这个。 我将服务参考添加到我上面提到的服务中,一切正常。 我可以实现并调用myservice1.GetData(100); 我得到了结果。

但有人告诉我,这项服务必须通过Web Services由Winforms .NET 2.0应用程序使用,因此我继续添加对从头创建的新Winforms .NET 2.0应用程序的引用(只有一个名为form1的winform)。 这次,在添加“web引用”时,它添加了属于webservices的典型“localhost”; 向导看到了WCF服务(在后台运行)并添加了它。

当我尝试使用它时,我发现GetData(int)方法现在是GetData(int,bool)。

这是代码

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

注意GetData调用中的false?

我不知道那个参数是什么或它来自哪里,它被称为“bool valueSpecified”。

有人知道这是从哪里来的吗? 我还应该做些什么来从.NET 2.0中将WCF服务用作WebService? (的WinForms)。

好吧……显然这里是答案和可能的解决方案或解决方法。