我想向您寻求帮助。我根据 Microsoft WebService 演练教程创建了 .net WebService。
这就是我的 IIS 结构。我有一个在本地主机和名为TemperatureWebService 的WebService 上运行的测试页面。 IIS screenshot
文件夹结构:使用浏览器访问localhost(或127.0.0.1),显示页面index.html(参见文件夹结构屏幕) Folder Structure
index.html 中使用的 JavaScript 如下。我通过 AJAX 向我的 WebService 发送虚拟 JSON 数据:
$(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 来做到这一点:
- 在 TestString 方法中设置断点
- 调试 -> 附加进程
- 我选择了打开页面的 chrome 进程(也许这不是最聪明的想法,但我相信它可以工作)
- 并在 Chrome 中刷新网站,但未命中断点。
我确信 WebService 可以工作,因为当我用简单的字符串测试它时,它返回了我需要的内容,但调试对我不起作用。我愿意接受任何改进,也许我没有设置正确的解决方案、代码或其他什么。如果有任何改进,我将不胜感激。谢谢。
罗伯特
最佳答案
在 VS 中打开项目。
如果TemperatureWebService项目配置为指向http://localhost/TemperatureWebService (右键单击 > 属性 > Web),也可以作为启动项目(右键单击 > 设置为启动项目),然后通过“运行”项目(在 VS 中按 F5)自动将调试器附加到关联的 IIS 进程。 .
如果自动调试器附加不起作用(有时它会比我上面描述的更复杂),则尝试手动附加:VS > 调试菜单 > 附加到进程 > 找到名为“w3pw.dll”的进程。 exe”(在不同版本的 Windows/IIS 上可能略有不同,但我很确定它的名称中包含“w3”或“www”)。
设置断点应该可以工作。
关于c# - 当我通过 Javascript AJAX 从页面发送 JSON 数据时,如何在 Visual Studio C# .net WebService 中命中断点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36925127/