本地调式问题

web.config标准配置如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <configuration>
  3. <appSettings>
  4. <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
  5. </appSettings>
  6. <system.web>
  7. <compilation debug="true" targetFramework="4.5.2"/>
  8. <httpRuntime targetFramework="4.5.2"/>
  9. </system.web>
  10. <system.serviceModel>
  11. <services>
  12. <service name="MapTemplateWCF.MapService" behaviorConfiguration="servicebehavior">
  13. <endpoint address="" binding="webHttpBinding" bindingConfiguration="" name="endpoint1" contract="MapTemplateWCF.IMapService"
  14. behaviorConfiguration="NewBehavior0"/>
  15. </service>
  16. </services>
  17. <behaviors>
  18. <endpointBehaviors>
  19. <behavior name="NewBehavior0">
  20. <enableWebScript/>
  21. <webHttp/>
  22. </behavior>
  23. </endpointBehaviors>
  24. <serviceBehaviors>
  25. <behavior name="servicebehavior">
  26. <serviceMetadata httpGetEnabled="true"/>
  27. <serviceDebug includeExceptionDetailInFaults="false"/>
  28. </behavior>
  29. </serviceBehaviors>
  30. </behaviors>
  31. <protocolMapping>
  32. <add binding="basicHttpsBinding" scheme="https"/>
  33. </protocolMapping>
  34. <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  35. </system.serviceModel>
  36. <system.webServer>
  37. <httpProtocol>
  38. <customHeaders>
  39. <add name="Access-Control-Allow-Origin" value="*"/>
  40. </customHeaders>
  41. </httpProtocol>
  42. <modules runAllManagedModulesForAllRequests="true"/>
  43. <!--
  44. To browse web app root directory during debugging, set the value below to true.
  45. Set to false before deployment to avoid disclosing web app folder information.
  46. -->
  47. <directoryBrowse enabled="true"/>
  48. </system.webServer>
  49. </configuration>

在VS2019中查看调试的配置:
image.png
获取调式的虚拟路径:
image.png
单击IIS调试:
image.png
单击后缀为svc的文件
image.png
出现以下界面说明配置无误,在URL栏中获取服务地址
image.png
此时web服务不要关掉,即要确保VS处于调试状态,并且你已经设置了断点:
image.png
打开Postman,创建一个新的连接,单击Send:
image.png
成功进入断点处:
image.png

远程调试问题

首先要发布一个IIS服务,且要求防火墙允许跨域访问(见文章:Win10让局域网内其他电脑通过IP访问网站的方法
这是我创建好的站点(物理路径中要包含web.config):
image.png
image.png
如下,web服务的访问没有任何问题
image.png
然后回到VS2019,在Debug Properties中进行如下设置:
image.png
然后再按照本地服务那样远程调试即可
如果出现对话框,里面内容显示:Unable to start debugging on the web server. You do not have permissions to debug the web server process. You need to either be running as…
image.png
确保所有用户的授权是完全控制
image.png
然后关闭VS2019,右击以管理员的权限运行,问题即可得解决。

参考资料

  1. stackoverflow :Unable to start debugging on the web server using visual studio 2012. https://stackoverflow.com/questions/24082215/unable-to-start-debugging-on-the-web-server-using-visual-studio-2012