不知道我在做什麼錯,但我有兩個服務,一個是WCF,另一個是ASMX服務。爲什麼WCF不像ASMX那樣工作?
我試圖調用雙精度數組,就像我在我的asmx版本中一樣。
下面是兩個服務的形象:
我有一個修復程序能夠調用該方法,但我想知道爲什麼ArrayOfDouble
沒有顯示出來以同樣的方式我的serviceref2作爲我的serviceref1?
這是WCF版本:
namespace WcfSum
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
[ServiceContract]
public interface SumListWCF
{
[OperationContract]
string CalculateSum(List<double> listDouble);
}
}
namespace WcfSum
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class SumList : SumListWCF
{
public string CalculateSum(List<double> listDouble)
{
return listDouble.Sum().ToString();
}
}
}
這是ASMX版本:
namespace CalculateWebServiceSum
{
/// <summary>
/// Summary description for Service1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class SumList : System.Web.Services.WebService
{
[WebMethod]
public string CalculateSum(List<double> listDouble)
{
return listDouble.Sum().ToString();
//return listDouble.Select(n => (double)n).ToString();
}
}
}
上一篇在這裏:WCF array of doubles not called successfully
這提供了修復,但並沒有解釋爲什麼它不以相同的方式操作。或者如果有辦法讓它採取相同的行動。這讓我覺得自己從根本上失去了一些東西?
編輯
P.S這些只是在本地運行。
對於WCF服務存在一種骯髒的小祕密:它們是如此的痛苦,以至於我知道現實世界中沒有人使用它們,如果他們有選擇的話。我們創建老式的ASMX,當我們在VS2010中添加服務引用時,我們轉到高級 - >添加Web引用,這樣事情就可以按照您的期望工作。 – 2012-03-15 18:56:44
WCF服務與ASMX服務不同。你爲什麼感到驚訝,他們是不同的? – Stilgar 2012-03-15 19:11:48
很多我認識的人在「現實世界」中使用WCF,我不知道大驚小怪,他們只是略有不同。我贊成WCF,因爲它最有可能得到Microsoft的持續支持和改進。 http://keithelder.net/2008/10/17/WCF-vs-ASMX-WebServices/ – Kekoa 2012-03-15 19:13:12