I am implementing a WCF service that needs to work with Json objects. This is working so far. Now, i want the service to accept https only, so no http.
For both requirements i have found a couple of samples that i have tested and that seem to work. However i am unable to get both requirements integrated into one config file.
This is my configuration for the service:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehavior" name="SMApi.SApi">
<endpoint address="" behaviorConfiguration="web" binding="webHttpBinding"
bindingConfiguration="" contract="SMApi.ISApi" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<!-- / -->
<behavior name="serviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<!-- / -->
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<!-- / -->
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
<!-- / -->
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="false"/>
</system.webServer>
</configuration>
Try adding a binding configuration for <webHttpBinding>
and setting the Security mode to transport. You'll need to explicitly set the binding configuration to your endpoint.
<bindings>
<webHttpBinding name="SMApiWebhttpBinding">
<security mode="Transport" />
</webHttpBinding>
</bindings>
Then in your endpoint reference the above binding configuration via the binding Configuration
attribute:
<service behaviorConfiguration="serviceBehavior"
name="SMApi.SApi">
<endpoint address="" behaviorConfiguration="web"
binding="webHttpBinding"
bindingConfiguration="SMApiWebHttpBinding"
contract="SMApi.ISApi" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.