debugging asp.net WCF service hosted in IIS

17,047

Solution 1

Before debugging you will have to deploy your dll and pdb to the IIS directory. Next, in your VS click debug-->Attach to process.. "Ensure to check Show process from all users" and "Show process in all sessions" you should now see W3WP process in your list of available process. Select W3WP and click attach.VS attach screenshot

You should now be able to debug the WCF service. please refer to following blogs for more debugging tips

http://dhawalk.blogspot.com/2007/07/debugging-tips-in-c.html http://anilsharmadhanbad.blogspot.com/2009/07/debugging-wcf-service-hosted-in-local.html

Solution 2

The "method not allowed" error when attempting to browse to the WCF's URL can occur for a variety of reasons:

1) The ASP.NET version is not configured correctly with IIS (re-run the aspnet_regiis.exe application for the appropriate version of .NET)

2) .svc files aren't mapped to use aspnet_isapi.dll (once again, re-run aspnet_regiis.exe)

3) IIS was installed after the WCF framework: for this one, you'd need to run this app, where 'xx' is the version of course: "%WINDIR%\Microsoft.Net\Framework\xx\Windows Communication Foundation\ServiceModelReg.exe" -r

Have a look at this article for a little further reading on IIS/ASP.NET configuration issues...

However, I've found the usual reason for "method not allowed" is due to a mistake I've made in the web.config: Something as simple as a typo in the binding information will cause it. Have a look at your web.config and make absolutely sure the URLs are correct.

If you've exhausted all these avenues and are still getting "method not allowed", try the Service Trace Viewer Tool, it could provide further information on what's going wrong.

Share:
17,047
DotnetSparrow
Author by

DotnetSparrow

I am working as asp.net freelance developer at eteksol. I have 7+ years of experience in asp.net/asp.net MVC/C#/SQl server.

Updated on June 13, 2022

Comments

  • DotnetSparrow
    DotnetSparrow almost 2 years

    I have created a WCF service using following template:

    http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd

    This service has a method like this:

    [ServiceContract]
        [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]    
        public class RecordingCompleted
        {
    
            [WebInvoke(UriTemplate = "", Method = "POST")]
            public string ProcessCall(string JsonData)
            {
    
            }
    
        }
    

    I have hosted this service on IIS and url of the method is:

    http://[local] host/Notifications/RecordingCompleted/

    When I type this address in address bar, I get:

    Method not allowed. Please see the service help page for constructing valid requests to the service.
    

    I am trying consume this web service using following code:

    string serviceBaseUrl = "http://[local] host/Notifications/RecordingCompleted/";

            string resourceUrl = "";
            string method = "POST";
            //string jsonText = "}";
            UseHttpWebApproach(serviceBaseUrl, resourceUrl, method, jsonText);
    

    and the methods are:

      private string UseHttpWebApproach(string serviceUrl, string resourceUrl, string method, string requestBody)
            {
                string responseMessage = null;
                var request = WebRequest.Create(string.Concat(serviceUrl, resourceUrl)) as HttpWebRequest;
                if (request != null)
                {
                    request.ContentType = "application/json";
                    request.Method = method;                 
                }
    
                //var objContent = HttpContentExtensions.CreateDataContract(requestBody);
                if (method == "POST" && requestBody != null)
                {
                    byte[] requestBodyBytes = ToByteArrayUsingJsonContractSer(requestBody);
                    request.ContentLength = requestBodyBytes.Length;
                    using (Stream postStream = request.GetRequestStream())
                        postStream.Write(requestBodyBytes, 0, requestBodyBytes.Length);
    
                }
    
                if (request != null)
                {
                    var response = request.GetResponse() as HttpWebResponse;
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Stream responseStream = response.GetResponseStream();
                        if (responseStream != null)
                        {
                            var reader = new StreamReader(responseStream);
    
                            responseMessage = reader.ReadToEnd();
                        }
                    }
                    else
                    {
                        responseMessage = response.StatusDescription;
                    }
                }
                return responseMessage;
            }
    
    
    
     private static byte[] ToByteArrayUsingJsonContractSer(string requestBody)
        {
            byte[] bytes = null;
            var serializer1 = new DataContractJsonSerializer(typeof(string));
            var ms1 = new MemoryStream();
            serializer1.WriteObject(ms1, requestBody);
            ms1.Position = 0;
            var reader = new StreamReader(ms1);
            bytes = ms1.ToArray();
            return bytes;
        }
    

    I am trying to debug the service method but I dont know how to do it. Please suggest me why I am getting error when I type http://[local] host/Notifications/RecordingCompleted/ in address bar. And how to debug the service which is hosted on local host ?

    Regards, Asif Hameed