调试asp.net WCF服务托管在IIS [英] debugging asp.net WCF service hosted in IIS

查看:101
本文介绍了调试asp.net WCF服务托管在IIS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试使用下面的模板创建一个WCF服务:

I have created a WCF service using following template:

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)
        {

        }

    }

我主持的这个IIS服务和方法的网址是:

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

HTTP:// [本地]主机/通知/ RecordingCompleted /

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.

我尝试使用以下code消耗该Web服务:

I am trying consume this web service using following code:

字符串serviceBaseUrl =HTTP:// [本地]主机/通知/ RecordingCompleted /;

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

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

和方法是:

  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;
    }

我想调试服务方法,但我不知道如何做到这一点。请建议我为什么我收到错误,当我键入
HTTP:// [本地]主机/通知/ RecordingCompleted /在地址栏。以及如何调试这是本地主机上托管的服务?

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

推荐答案

调试你将有你的DLL和PDB部署到IIS目录之前。接下来,在你的VS点击调试 - >附加到进程。确保所有用户检查显示进程和显示过程中的所有会话你现在应该看到可用的进程列表W3WP过程。选择W3WP并单击连接。

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.

您现在应该能够调试WCF服务。请参考下面的博客更多的调试提示

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 /调试-提示功能于c.html
http://anilsharmadhanbad.blogspot.com/2009/07/debugging-wcf-service-hosted-in-local.html

这篇关于调试asp.net WCF服务托管在IIS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆