调试IIS中托管的asp.net WCF服务

Dot*_*row 5 asp.net iis wcf iis-7

我使用以下模板创建了一个WCF服务:

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

这项服务有这样的方法:

[ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]    
    public class RecordingCompleted
    {

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public string ProcessCall(string JsonData)
        {

        }

    }
Run Code Online (Sandbox Code Playgroud)

我在IIS上托管了这个服务,该方法的url是:

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

当我在地址栏中输入此地址时,我得到:

Method not allowed. Please see the service help page for constructing valid requests to the service.
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码使用此Web服务:

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

        string resourceUrl = "";
        string method = "POST";
        //string jsonText = "}";
        UseHttpWebApproach(serviceBaseUrl, resourceUrl, method, jsonText);
Run Code Online (Sandbox Code Playgroud)

方法是:

  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;
    }
Run Code Online (Sandbox Code Playgroud)

我正在尝试调试服务方法,但我不知道该怎么做.当我在地址栏中键入http:// [local] host/Notifications/RecordingCompleted /时,请建议我为什么会收到错误.以及如何调试托管在本地主机上的服务?

此致,Asif Hameed

Dha*_*alk 12

在调试之前,您必须将dll和pdb部署到IIS目录.接下来,在您的VS中单击调试 - >附加到进程.."确保选中显示所有用户的进程"和"在所有会话中显示进程",您现在应该在可用进程列表中看到W3WP进程.选择W3WP并单击附加.VS附加截图

您现在应该能够调试WCF服务.有关更多调试技巧,请参阅以下博客

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