C# 如何调试 Web 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12581932/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug Web Service?
提问by urz shah
I am using visual studio and I have asp.net application as one project and a web service as another project.I am using web service in my asp.net application. There is some sort of problem im my webservice code.But i am unable to debug continuosly from asp.net application to web service.I put break point both in application and web service but break point not activated in web service and it shows me connection error.How can i do this while hosting on localhost?
我正在使用 Visual Studio,我将 asp.net 应用程序作为一个项目,将 Web 服务作为另一个项目。我在我的 asp.net 应用程序中使用 Web 服务。我的 web 服务代码存在某种问题。但是我无法从 asp.net 应用程序连续调试到 web 服务。我在应用程序和 web 服务中都设置了断点,但在 web 服务中未激活断点,它显示了我的连接错误。如何在本地主机上托管时执行此操作?
采纳答案by Mehmet Osmanoglu
If you're running web application as startup project, try running web service in another debug instance.
如果您将 Web 应用程序作为启动项目运行,请尝试在另一个调试实例中运行 Web 服务。
You can do it by right-clicking on web service project, Debug -> Start new instance
您可以通过右键单击 Web 服务项目,调试 -> 启动新实例来完成
回答by NiladriBose
Is the web service running on a remote computer , if so you need to setup remote debug for the web service.
Web 服务是否在远程计算机上运行,如果是,您需要为 Web 服务设置远程调试。
回答by Cybermaxs
回答by Krunal Solanki
If you want to debug in local system, You can set multiple start up projects. You can set multiple startup by Solution properties. Hope this help
如果要在本地系统调试,可以设置多个启动项目。您可以通过解决方案属性设置多个启动。希望这有帮助
回答by Rob
Try to debug the service itself and see if it hits breakpoint. Just set the project that has service in it to be the main project and set the service to be the main start page.
尝试调试服务本身,看看它是否命中断点。只需将其中包含服务的项目设置为主项目并将服务设置为主启动页面即可。
If it doesn't hit the breakpoint it probably didn't load all the symbols. That happens if the project is set to, lets say, Release configuration and not Debug.
如果它没有到达断点,它可能没有加载所有符号。如果项目设置为发布配置而不是调试,就会发生这种情况。
回答by Rajpurohit
Can You please check that you add Service reference your web service or not other you can't access your web service function. I am useing web service in my project like this it's below
请检查您添加的服务是否引用了您的网络服务,否则您无法访问您的网络服务功能。我在我的项目中使用网络服务,如下所示
this is my web service code
这是我的网络服务代码
[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 JsonData : System.Web.Services.WebService
{
[WebMethod(Description = "")]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public StateData[] GetStateByCountryID(int ID)
{
StateData objStateData = new StateData();
LMGDAL.db_LMGEntities dbData = new db_LMGEntities();
var data = (from con in dbData.tblStates
where con.State_CountryID == ID
select new StateData
{
StateID = con.StateID,
StateName = con.StateName
}).ToList();
return data.ToArray();
}
then i add Service reference to my asp.net web form
然后我将服务引用添加到我的 asp.net web 表单
this code in my form
这个代码在我的表单中
<script type="text/javascript">
$(function () {
$("#ddlCountry").change(function () {
var countryID = $("#ddlCountry").val();
$.ajax({
type: "POST",
url: "JsonData.asmx/GetStateByCountryID",
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: '{ID:"' + countryID + '"}',
success: function (msg) {
var data = msg.d;
var stateData = "";
$.each(data, function (index, itemdata) {
stateData += "<option value='" + itemdata.StateID + "' > " + itemdata.StateName + " </option>";
});
$("#ddlState").empty();
$("#ddlState").append("<option value='0'>-Select State-</option>");
$("#ddlState").append(stateData);
},
error: function () {
alert('Faild To Retrieve States.');
}
});
});
I think this will help you
我想这会帮助你

