How to debug Web Service?

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If you’re running web application as startup project, try running web service in another debug instance.

You can do it by right-clicking on web service project, Debug -> Start new instance

Method 2

You should attach the debugger to w3wp (IIS process).

Here is a link that could help you.

Method 3

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

Method 4

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.

Method 5

Is the web service running on a remote computer , if so you need to setup remote debug for the web service.

Method 6

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

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x