Error Message 1:
calling WCF https, returns EndpointNotFoundException: There was no channel actively listening at 'https://xxxx. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent.
Error Message 2:
405 Method not allowed.
Error Message 3:
Error in '/' Application. The resource cannot be found.
Error Message 4 on client side:
HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier)
What is the issue?
When the Ajax JS calls the WCF service with a restful Json/XML format, it is actually violating the crossing_domain rule. The asp.net is not allowing the crossing domain scripting so we need to turn it on first before we call WCF.
eg. crossDomainScriptAccessEnabled="true"
Solution:
1. Open the Web.config file.
2. Make sure you have all below setting and test it.
<system.serviceModel>
<!--You may want to provide multiple base addresses that use the same protocol on the same site. Set it to true if you want to.
eg. sample.com or www.sample.com-->
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
<behaviors>
<endpointBehaviors>
<behavior name="eb_web_based_wcf">
<webHttp helpEnabled="true" />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="sb_wcf_behavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="wcf_rest_classes.wrc_wcf_class" behaviorConfiguration="sb_wcf_behavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="ssl_https_binding" contract="wcf_rest_classes.Iwrc_wcf_class" behaviorConfiguration="eb_web_based_wcf"/>
</service>
</services>
<!-- Important: This is a setting for the Resful Json WCF -->
<bindings>
<webHttpBinding>
<binding name="ssl_https_binding" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="http_bind" crossDomainScriptAccessEnabled="true">
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
- end -
My kind suggestion No1:
I saw someone tried to run an “add header” function on the Global.asax as below. I am not sure whether it is working or not. But, this solution likely will slow down a website performance because it will be called every time when the page being accessed. Personally, I never put anything on the Global.asax.
protected void Application_BeginRequest(object sender, EventArgs e)
{ //this is not a good solution.
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "https://xxx");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}
My Kind suggestion No2:
You should encrypt your Input parameters on the JS client side because the url can be duplicated. It is good to have ssl for communication but ssl does not guarantee the url safty. For banking website, if we use a client side http request then we must use a Dynamic AES Encrypted Token every time when the WCF being called by JavaScript.