【发布时间】:2012-03-15 18:38:01
【问题描述】:
不知道我做错了什么,但我有两个服务,一个是 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 中添加服务引用时,我们转到 Advanced->Add Web Reference,这样事情就会按照您的预期进行。
-
WCF 服务与 ASMX 服务不同。为什么你会对它们的不同感到惊讶?
-
我认识的很多人在“现实世界”中使用 WCF,我不知道大惊小怪,他们只是略有不同。我倾向于 WCF,因为它最有可能得到 Microsoft 的持续支持和改进。 keithelder.net/2008/10/17/WCF-vs-ASMX-WebServices
-
这不是真的吗?另外,我尝试了高级选项来添加 web ref 并不能完全按照我想要的方式工作。如果您可以直观地添加一个网络参考并添加您想要的方法,那将是非常好的。我确定它的服务和运营合同有点我错了。
-
@Garrith 我在代码中的任何地方都看不到
ArrayOfDouble。如果接口中没有引用该类型,它就不会出现在服务引用中。
标签: c# asp.net wcf web-services soap