I tried to call a method in WCF service to retrieve a list of countries using jQuery but I was prompted with "Access is denied" in the following js line:
Is your service containig required decoration which work with http post?
Here are few...
Your service contract should decorated with [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Your operation contract should decorated wih [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
You need webHttpBinding biding for work with AjaxEnable service. which includes enbpoint behaviour having enableWebScript, so config should look like this...
whchoo
Member
1 Points
3 Posts
Access is denied when using jQuery to post a request to WCF
Jun 18, 2010 07:21 AM|LINK
Hi,
I tried to call a method in WCF service to retrieve a list of countries using jQuery but I was prompted with "Access is denied" in the following js line:
e.username?x.open(n,e.url,e.async,e.username,e.password):x.open(n,e.url,e.async);
I'd not such problem if calling the method in CodeBehind.
ASPX
<asp:DropDownList ID="Country1" runat="server"></asp:DropDownList>
<script type="text/jscript">
$(document).ready(function () {
// JSONify the data
var data = JSON.stringify("");
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "http://localhost:8080/RealNorthwindService/Product/GetActiveCountrySelectList",
data: data,
dataType: "json",
success: callback
});
});
function callback(result) {
var newModel = result["d"];
if (result == "success") {
alert("Model " + newModel.ModelName + " added!");
} else {
alert("Could not add model!");
}
}
</script>
Code-Behind
List<CountrySelectListItem> countries = productSvc.GetActiveCountrySelectList();
Country1.DataSource = countries;
Country1.DataTextField = "Text";
Country1.DataValueField = "Value";
Country1.DataBind();
web.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IProductService"
closeTimeout="00:02:00" openTimeout="00:02:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/RealNorthwindService/Product/ProductService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IProductService"
contract="ProductServiceReference.IProductService"
name="WSHttpBinding_IProductService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
JQuery
bhadelia.imr...
Contributor
3191 Points
533 Posts
Re: Access is denied when using jQuery to post a request to WCF
Jun 18, 2010 07:38 AM|LINK
Is your service containig required decoration which work with http post?
Here are few...
Your service contract should decorated with [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Your operation contract should decorated wih [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
You need webHttpBinding biding for work with AjaxEnable service. which includes enbpoint behaviour having enableWebScript, so config should look like this...
<service name="YourServiceName"> <endpoint address="" behaviorConfiguration="AspNetAjaxBehavior" binding="webHttpBinding" contract="YourContact" /> </service>and here is her is behaviorConfiguration
<endpointBehaviors> <behavior name="BattleEmpire.Web.Services.UserAvailabilityServiceAspNetAjaxBehavior"> <enableWebScript /> </behavior> </endpointBehaviors>JQuery & WCF enableWebScript
[MCTS]
Born to fly High
http://knowledgebaseworld.blogspot.com/
sandy060583
Star
8714 Points
1624 Posts
Re: Access is denied when using jQuery to post a request to WCF
Jun 19, 2010 09:39 AM|LINK
try this link :
http://www.west-wind.com/weblog/posts/896411.aspx
This might help you to overcome this issue
Ramani Sandeep (My Blog)
(MCTS, MCC-2011)