c# - 找不到资源,wcf
问题描述
这是我的 wcf 服务配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="db-connection-string.config">
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpTransportSecurity">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="PingServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<services>
<service name="PingService.PingService" behaviorConfiguration="PingServiceBehavior">
<endpoint address="ws" binding="wsHttpBinding" contract="PingService.IPingService" />
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="WebBehavior" contract="PingService.IPingService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
这是服务:
namespace PingService
{
[ServiceContract]
public interface IPingService
{
[WebGet]
[OperationContract]
string Hello();
}
}
当我在浏览器中输入:https://localhost/PingService/PingService.svc/hello 浏览器显示错误:
无法找到该资源。
解决方案
这个配置解决了我的问题:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="db-connection-string.config">
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<customErrors mode="Off"/>
<compilation targetFramework="4.6" />
<httpRuntime targetFramework="4.6" />
</system.web>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="SecureWebBinding">
<security mode="Transport" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="PingServiceBehavior">
<serviceMetadata httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SOAPDemoEndpointBehavior">
</behavior>
<behavior name="RESTDemoEndpointBehavior">
<webHttp />
</behavior>
<behavior name="mexBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"></serviceHostingEnvironment>
<services>
<service name="PingService.PingService" behaviorConfiguration="PingServiceBehavior">
<endpoint address="rest" binding="webHttpBinding" bindingConfiguration="SecureWebBinding" behaviorConfiguration="RESTDemoEndpointBehavior" contract="PingService.IPingService" />
<endpoint address="soap" binding="basicHttpBinding" behaviorConfiguration="SOAPDemoEndpointBehavior" contract="PingService.IPingService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
推荐阅读
- laravel - 对数据库计数的结果不同
- azure-api-management - set-base-url 总是在后端部分重置
- android - Android 10 - 找不到处理 Intent 的 Activity
- javascript - 如何使用 Jest 和 Enzyme 在 React 中测试 OnSubmit
- javascript - 如何使用 KnockoutJS 根据来自 AJAX 调用的值设置下拉列表?
- javascript - 未捕获的类型错误:无法读取未定义的属性“0”,因为它不存在
- javascript - 我怎样才能控制我的多重
在视图里面? - python - Python 将#U0048 样式的 unicode 转换为普通字符串
- linux - 用于 linux 部署后操作的 azure webapp
- java - java 中的 try 或 catch 中的 return 是如何工作的?