简体   繁体   English

从.asmx升级到razor中的WCF

[英]Upgrade from .asmx to WCF in razor

So I have been calling a method from ac# class from Razor using a .asmx file, and I have learned that .asmx is deprecated. 因此,我一直在使用.asmx文件从Razor的ac#类调用一种方法,并且我了解到.asmx已被弃用。 I'm trying to figure out what to replace this method with. 我试图弄清楚用什么代替这种方法。 Here's what I'm doing now: 这是我现在正在做的事情:

The C# program (GetConstantContactData.cs) looks like this: C#程序(GetConstantContactData.cs)如下所示:

using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;




/// <summary>
/// Summary description for GetConstantContactData
/// </summary>
[WebService(Namespace = "https://[myurl].org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 GetConstantContactData : System.Web.Services.WebService {


 public string GetResponse()
    {
      //Get data from Constant Contact and return it as a JSON string
    }

The .asmx file (GetConstantContactData.asmx) looks like this: .asmx文件(GetConstantContactData.asmx)如下所示:

<%@ WebService Language="C#" CodeBehind="~/App_Code/GetConstantContactData.cs" Class="GetConstantContactData" %>

And the Javascript ajax calls the .asmx file like this: Javascript ajax像下面这样调用.asmx文件:

$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../GetConstantContactData.asmx/GetResponse",
data: "{}",
success: SucceededCallback,
error: FailedCallback,
dataType: "json"
})
// Callback function that
// processes the service return value.
function SucceededCallback(result) {
     //do stuff with the data
}

It works now, but as I said I know this method is deprecated, and doesn't work in .NET 4. As I understand it I want to do this through WCF using a ServiceHost. 它现在可以使用,但是正如我所说,我知道该方法已被弃用,并且在.NET 4中不起作用。据我了解,我想通过WCF使用ServiceHost来实现。 I see how to do this using a ScriptManager here , but I want to know how to do it using Razor. 在这里看到了如何使用ScriptManager来执行此操作,但是我想知道如何使用Razor来执行此操作。

I've been searching the web for any kind of tutorial or guide on this. 我一直在网上搜索有关此问题的任何教程或指南。 Just a link to the correct place to tell me how to do this would be great. 只需链接到正确的位置以告诉我如何执行此操作就很好。 Thank you. 谢谢。

Brent Mannering's suggestion of the WebAPI endpoint above was the best answer to this problem. 布伦特·曼纳宁(Brent Mannering)对以上WebAPI端点的建议是对此问题的最佳答案。 It doesn't use WCF, but the Web API is a more useful lightweight solution to this problem that matches with what I was originally doing with the .asmx Webservice framework, and which is not deprecated. 它不使用WCF,但是Web API是解决此问题的更有用的轻型解决方案,它与我最初使用.asmx Webservice框架进行的操作相匹配,并且不建议使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM