【发布时间】:2014-04-09 19:31:39
【问题描述】:
我在谷歌上搜索知道我们如何轻松地将 asmx 服务转换为 wcf,我看到人们编写类似的代码
这是我的旧 asmx 服务
[WebService(Namespace="http://kennyw.com/sampleservices/")]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
public string Hello(string name)
{
return string.Format(“Hello {0}.”, name);
}
}
转换为 wcf
[ServiceContract(Namespace="http://kennyw.com/WCFservices/")]
[WebService(Namespace="http://kennyw.com/sampleservices/")]
public class MyService : System.Web.Services.WebService
{
[WebMethod]
[OperationContract]
public string Hello(string name)
{
return string.Format(“Hello {0}.”, name);
}
}
我在转换时看到人们没有使用服务合同接口。它将如何工作,因为我知道当我们开发 wcf 服务时,我必须为单个服务编写一个服务合同接口。所以寻找讨论如何在没有服务合同接口的情况下开发 wcf 服务。谢谢
【问题讨论】:
-
有点不清楚你在问什么。您不必必须编写单独的接口,但这是可测试性和可重用性的好习惯。
-
嗯...它编译了吗?这行得通吗?
-
如果有问题,您可以将其转换为 ASP.NET Web API 服务。
标签: c# web-services wcf servicecontract