Can anyone spot what is wrong with my code? I'm getting a 404 Not Found on firebug when i use jQuery to call a WCF SOAP service.
I'm on Win7 using IIS7. I have the wcf running on a virtual directory application as (http://localhost/csw). I can access the service.svc file with no problem here at this url: (http://localhost/csw/service.svc)
Here is my Web.config between the configuration tags
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name ="soapBinding">
<security mode="None">
</security>
</binding>
</basicHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="CatalogService" behaviorConfiguration="defaultBehavior">
<endpoint address="soap"
binding="basicHttpBinding"
bindingConfiguration="soapBinding"
contract="ICatalogService" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="xmlBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="defaultBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception inf开发者_运维技巧ormation -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
App_Code/ICatalogServices.cs:
[ServiceContract(Namespace = "http://test/CatalogService")] public interface ICatalogService {
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.Wrapped,
ResponseFormat = WebMessageFormat.Xml,
RequestFormat = WebMessageFormat.Xml)]
string HelloWorld(string name);}
App_Code/CatalogServices.cs:
public class CatalogService : ICatalogService{
public string HelloWorld(string name){
return String.Format("Hello {0}", name);}}
jQuery call:
$.ajax({
type: 'POST',
url: 'http://localhost/csw/service.svc/HelloWorld',
data: request,
contentType: 'application/xml; charset=utf-8',
dataType: 'xml',
success: function (result) {
console.log(result);
$("#result").text(result);
//result.responseXML
//result.responseText
},
error: function (message) {
console.log(message);
alert("error has occured" + message);
}
});
my request xml is:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body> <HelloWorld xmlns="http://test/CatalogService"> <name>CarlosK</name> </HelloWorld> </s:Body> </s:Envelope>
URL in your jQuery code is wrong. Try to use http://localhost/csw/service.svc/soap. Also change content type to text/xml; charset=utf-8
Edit:
Address: The operation name is not part of URL when calling SOAP service. (in contrast to REST services). Also in your configuration you have defined relative address for SOAP endpoint. Valid URL is BaseAddress + /service.svc + /RelativeAddress. Based address is defined by your virtual directory.
Content Type: You are exposing the service on BasicHttpBinding. BasicHttpBinding uses SOAP 1.1. Correct content type for SOAP 1.1 is text/xml and charset.
Edit for new error:
The new error says that it can't route empty action to operation in your service. You have to add SOAPAction HTTP header to your request build by jQuery. Value for the header should be http://test/CatalogService/ICatalogService/HelloWorld
精彩评论