I created a WCF SOAP service using VS 2008 that works server side. I tacked on the code below to call the same service/contract client side using jQuery/json (no ASP.NET scriptmanager). When I put the service url into the browser, I get the correct service page and when I invoke the service from javascript and trace via Firebug, I get "405 method not allowed".
The ajax() error function's statusText and and responseText contain nothing and the error function gets called twice for some strange reason. I'm also invoking the service from an https page.
The same ajax code works with a similar traditional webservice both server side and client side and also works with a page method.
Any clues? I also noticed my Windows Communication Foundation HTTP Activation and Non-HTTP Activation are not installed. Do I need these? My server side WCF service works though.
Interface:
[ServiceContract]
public interface ICust
{
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
bool GetCust(string zzz);
}
Class:
public class Cust: ICust
{
public bool GetCust(string zzz)
{
// Do Stuff
// Return true/false;
}
}
web.config:
<behaviors>
<serviceBehaviors>
<behavior name="E.W.CustomerBehavior" >
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="webCallable">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="E.W.CustomerBehavior"
name="E.W.Customer">
<endpoint address="http://zzzz/Cust.svc"
binding="webHttpBinding"
contract="E.W.ICust"
behaviorConfiguration="webCallable">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
jQuery:
$.ajax({
cache: false,
async: false,
type: "POST",
url: "http://zzzz/Cust.svc/GetCust",
contentType: "application/json",
dataType: "json",
data: "{'zzz': '" + $("#ctl00_zz_zzz").val() + "'}",
success: function(msg) {
// do stuff
},
error: function(z) { alert(z.responseText); }
});