tags:

views:

30

answers:

1

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 information -->
                <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/"&gt;  <s:Body>  <HelloWorld xmlns="http://test/CatalogService"&gt;  <name>CarlosK</name>  </HelloWorld>  </s:Body>  </s:Envelope>
+1  A: 

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

Ladislav Mrnka
Excellent, i've changed the URL in the jQuery code and the content type and i get a different error (The message with Action '' cannot be processed at the receiver...) which i believe your "Address" and "Content Type" sections of your response address. Could you give me an example of the valid URL (BaseAddress + /service.svc + /RelativeAddress). (http://localhost/csw/service.svc/???)
krefftc
That is a good error because it means that you are already calling the service so the address is correct.
Ladislav Mrnka
wait... nevermind. i'm getting a seperate issue error now which i will ask another question for.
krefftc
Don't start new question - I have edited my answer.
Ladislav Mrnka
Thank you so much. I don't see how i would specifying this in the requesting jQuery header though (http://www.tutorialspoint.com/jquery/ajax-jquery-ajax.htm) Any ideas?
krefftc
I'm jQuery noob. I can help you with SOAP and WCF but for jQuery you need somebody else.
Ladislav Mrnka
Thanks for all your help though... i think i might need mootools for this one.
krefftc
IIRC, you can add a beforeSend function that gets the XHR object and can add the header from that callback.
superfell