我在VS2008中創建了默認的WCF服務。這就是所謂的 「服務1」WCF作爲WebService消耗添加一個布爾參數?
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應用程序來「測試」這個。我在上面提到的服務中添加了服務引用,它都可以工作。我可以instanciate並調用myservice1.GetData(100);我得到結果。
但我被告知該服務將不得不由Winforms .NET 2.0應用程序通過Web服務使用,所以我開始添加對從頭創建的新Winforms .NET 2.0應用程序的引用(只有一個名爲winform的form1中)。這一次,當添加「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調用假?
我不知道該參數是什麼或來自哪裏,它被稱爲「bool valueSpecified」。
有沒有人知道這是從哪裏來的?還有什麼我應該做的以從.NET 2.0中將Web服務用作WCF服務? (的WinForms)。
與XML序列化相同的警告:) – leppie 2010-03-31 12:47:11