I have a REST WCF Service that works fine on localhost but returns the below error when deploying online:
The resource cannot be found.
Note: My WCF service is located under the following path:
https://example.com/api/v1/Service.svc
I am pretty sure that the problem is a path error and I tried too many solutions but none worked.
Below is my Web.config
:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Service">
<endpoint address="" binding="webHttpBinding" contract="IService" behaviorConfiguration="JsonBehavior" listenUri="/">
<identity>
<dns value="" />
</identity>
</endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding crossDomainScriptAccessEnabled="true" maxBufferSize="2000000000" maxReceivedMessageSize="2000000000" transferMode="Buffered">
<readerQuotas maxDepth="250000000" maxStringContentLength="250000000" maxArrayLength="250000000" maxBytesPerRead="250000000" maxNameTableCharCount="250000000" />
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="JsonBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="0" multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
</system.serviceModel>
Solution 1:
Adding a base address to system.serviceModel > Services > Service
<host>
<baseAddresses>
<add baseAddress="https://example.com/" />
</baseAddresses>
</host>
Solution 2:
Adding a base address prefix to system.serviceModel > serviceHostingEnvironment
<baseAddressPrefixFilters>
<add prefix="https://example.com/" />
</baseAddressPrefixFilters>
Solution 3:
Playing around with the endpoint address
and listenUri
<endpoint address="https://example.com/api/v1/Service.svc" binding="webHttpBinding" contract="IService" behaviorConfiguration="JsonBehavior" listenUri="/">
How can I define the correct path in my Web.config
?
Note: In another project, I had my .svc
file on the root directory and I used the same Web.config
I posted above and everything worked fine. So it is definitely a path problem.
Finally, I solved the problem by changing <security mode="Transport" />
and it worked!