Reputation: 1810
I see a bunch of examples online but I am confused as to whether the service should be stand-alone or in the same solution as the consuming application. Can someone please help me?
Do I need to add a file of type AJAX-enabled WCF Service to my ASP.NET web application or do I need a Web Service reference to my WCF Service?
When I use the jQuery Ajax function there is a URL parameter. All the examples I see use "Services/MyService.svc/MyMethodName
". Is this because the service is inside of the web application's solution?
Does my WCF Service have to have:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
Do my web service calls need to have the following attributes?
[WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
Does my web application or my web service need the behavior set to enableWebScript
?
Did I miss any required attributes or settings?
Here is my jquery ajax request in my web application:
$.ajax({
type: "POST",
url: "http://myserver/myservice.svc/mymethod",
contentType: "application/json; charset=utf-8",
data: "{" + args + "}",
dataType: 'json',
});
Here is my web service web.config:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="Basic" />
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyServiceName">
<endpoint address="basic"
binding="basicHttpBinding"
bindingConfiguration="Basic"
name="Basic"
contract="IService" />
<endpoint address="web"
behaviorConfiguration="webHttpBehavior"
binding="webHttpBinding"
name="Web"
contract="IService" />
<endpoint address="mex"
binding="mexHttpBinding"
name="Metadata"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Upvotes: 2
Views: 3217
Reputation: 126
Include
<serviceMetadata httpGetEnabled="true"/>
in your service endpoint behavior.
Upvotes: 3