简体   繁体   English

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

[英]debugging asp.net WCF service hosted in IIS

I have created a WCF service using following template: 我使用以下模板创建了一个WCF服务:

http://visualstudiogallery.msdn.microsoft.com/fbc7e5c1-a0d2-41bd-9d7b-e54c845394cd 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: 我在IIS上托管了这个服务,该方法的url是:

http://[local] host/Notifications/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.

I am trying consume this web service using following code: 我正在尝试使用以下代码使用此Web服务:

string serviceBaseUrl = "http://[local] host/Notifications/RecordingCompleted/"; 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. 当我在地址栏中键入http:// [local] host / Notifications / RecordingCompleted /时,请建议我为什么会收到错误。 And how to debug the service which is hosted on local host ? 以及如何调试托管在本地主机上的服务?

Regards, Asif Hameed 此致,Asif Hameed

Before debugging you will have to deploy your dll and pdb to the IIS directory. 在调试之前,您必须将dll和pdb部署到IIS目录。 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. 接下来,在您的VS中单击调试 - >附加到进程..“确保选中显示所有用户的进程”和“在所有会话中显示进程”,您现在应该在可用进程列表中看到W3WP进程。 Select W3WP and click attach. 选择W3WP并单击附加。 VS附加截图

You should now be able to debug the WCF service. 您现在应该能够调试WCF服务。 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 http://dhawalk.blogspot.com/2007/07/debugging-tips-in-c.html http://anilsharmadhanbad.blogspot.com/2009/07/debugging-wcf-service-hosted-in-local.html

The "method not allowed" error when attempting to browse to the WCF's URL can occur for a variety of reasons: 尝试浏览WCF的URL时出现“方法不允许”错误的原因有多种:

1) The ASP.NET version is not configured correctly with IIS (re-run the aspnet_regiis.exe application for the appropriate version of .NET) 1)使用IIS未正确配置ASP.NET版本(为适当版本的.NET重新运行aspnet_regiis.exe应用程序)

2) .svc files aren't mapped to use aspnet_isapi.dll (once again, re-run aspnet_regiis.exe) 2).svc文件未映射为使用aspnet_isapi.dll(再次运行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 3)在WCF框架之后安装了IIS:对于这个,您需要运行此应用程序,其中'xx'是课程的版本:“%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... 看看这篇文章 ,进一步阅读IIS / ASP.NET配置问题...

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. 但是,我发现“方法不允许”的常见原因是由于我在web.config中犯了一个错误:绑定信息中的拼写错误会引起它。 Have a look at your web.config and make absolutely sure the URLs are correct. 看看你的web.config并确保URL正确无误。

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. 如果您已经用尽了所有这些途径并且仍然“不允许使用方法”,请尝试使用服务跟踪查看器工具 ,它可以提供有关出错的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET ExecutionTimeout对IIS托管的WCF服务无效 - ASP.NET ExecutionTimeout no effect on IIS-hosted WCF service 如何从Asp.net 2.0使用IIS托管的WCF服务 - How to Comsume IIS Hosted WCF Service from Asp.net 2.0 从IIS中托管的ASP.NET Web应用接收WCF回调服务 - Receiving a WCF callback service from a ASP.NET web app hosted in IIS 如何处理ASP.NET网页和IIS中托管的WCF服务之间的跨域请求? - How to handle cross domain request between an asp.net web page and a WCF service hosted in IIS? 与Windows服务上托管的WCF服务的ASP.net服务器连接 - ASP.net server connection with WCF service hosted on windows service ASP.NET,WCF:使用本地Windows服务中托管的WCF服务的ASP.NET应用程序 - ASP.NET, WCF: ASP.NET application consuming WCF service hosted in a local windows service ASP.NET网站中托管的WCF服务-Windows身份验证不起作用 - WCF Service Hosted in ASP.NET website - Windows Authentication not working Silverlight和带有自托管WCF服务的ASP.NET AuthenticationService? - Silverlight and ASP.NET AuthenticationService with self-hosted WCF Service? Asp.net 自托管 WCF 服务 WSDL 与相对路径 - Asp.net Self Hosted WCF Service WSDL with relative paths 使用Autofac将DI转换为ASP.NET应用程序中托管的WCF服务 - Using Autofac for DI into WCF service hosted in ASP.NET application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM