gpt4 book ai didi

c# - 当我通过 Javascript AJAX 从页面发送 JSON 数据时,如何在 Visual Studio C# .net WebService 中命中断点

转载 作者:行者123 更新时间:2023-11-30 23:26:17 24 4
gpt4 key购买 nike

我想请你帮忙。我已经根据 Microsoft WebService Walkthrough 教程创建了 .net WebService。

这就是我的 IIS 结构的样子。我有一个在本地主机和名为 TemperatureWebService 的 WebService 上运行的测试页面。 IIS screenshot

文件夹结构:用浏览器访问localhost(或127.0.0.1),显示页面index.html(文件夹结构见屏幕) Folder Structure

index.html 中使用的 Javascript 如下。我正在通过 AJAX 将虚拟 JSON 数据发送到我的 Web 服务:

$(document).ready(function () {
var datas = JSON.stringify({ datas: { premenna: "hodnota", jozko: "123" } });
$.ajax({
type: "POST",
url: "TemperatureWebService/Convert.asmx/TestString",
dataType: "json",
data: datas,
contentType: "application/json; charset=utf-8",
success: function (msg) {
console.log('success' + msg);
},

});
});

这是CS服务代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.Script.Serialization;

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

public Convert () {

//Uncomment the following line if using designed components
//InitializeComponent();
}

public class RootObject
{
public string premenna;
public string jozko;
}

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string TestString(RootObject datas)
{
string skuska = datas.premenna;
return skuska;
}
}

我想做的是在 TestString 方法中设置一个断点。我尝试用 Visual Studio 来做:

  1. 在TestString方法中设置断点
  2. 调试 -> 附加进程
  3. 我选择了打开页面的 chrome 进程(也许这不是最聪明的主意,但我相信它可行)
  4. 并在 chrome 中刷新了站点,但没有命中断点。

我确信 WebService 可以工作,因为当我用简单的字符串对其进行测试时,它返回了我需要的内容,但调试对我不起作用。我愿意接受任何改进,也许我没有正确设置解决方案、代码或其他任何东西。如果有任何改进,我将不胜感激。谢谢。

罗伯特

最佳答案

在 VS 中打开项目。

  1. 如果 TemperatureWebService 项目配置为指向 http://localhost/TemperatureWebService (右键单击 > 属性 > web),也作为启动项目(右键单击 > 设置为启动项目),然后通过“运行”项目(在 VS 中按 F5)自动将调试器附加到关联的 IIS 进程.

  2. 如果 automatic-debugger-attach 不起作用(有时它比我上面描述的更复杂),请尝试手动附加:VS > 调试菜单 > 附加到进程 > 找到名为“w3pw.process”的进程。 exe”(在不同版本的 Windows/IIS 上可能略有不同,但我很确定它的名称中有“w3”或“www”)。

然后设置断点应该起作用。

关于c# - 当我通过 Javascript AJAX 从页面发送 JSON 数据时,如何在 Visual Studio C# .net WebService 中命中断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com