title: How to call a WCF service from javascript?
body: <p>I'm trying to call a WCF service from an ajax call with jQuery.
  I manage to call the WCF from SOAP-UI and from Excel/VBA.
  My problem comes from the OPTIONS request that's sent and no POST follows:</p>
  
  <ul>
  <li>if I set URL to <code>http://mywcf/service.svc</code>, OPTIONS is sent and I get a <code>400 Bad Request</code> status and POST request is not sent. In this case, there's missing <code>HTTP/1.1</code> in header (comparing with SOAP-UI headers).</li>
  <li>if I set URL to <code>http://mywcf/service.svc HTTP/1.1</code>, OPTIONS is sent and I get a <code>200 OK</code> status but POST request is not sent. In this case, <code>HTTP/1.1</code> seems to be interpreted as a filename.</li>
  </ul>
  
  <p>Can someone tell me how to call a POST action on a WCF from javascript and to add <code>HTTP/1.1</code> header without corrupting service URL?</p>
  
  <p>Here is a extract from my ajax call:</p>
  
  <pre><code>var soapData = ''
          +'&lt;soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:mic="http://microsoft.wcf.documentation"&gt;'
          +'    &lt;soap:Header xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsrm="http://docs.oasis-open.org/ws-rx/wsrm/200702"&gt;'
          +'        &lt;wsrm:Sequence&gt;'
          +'            &lt;wsrm:Identifier&gt;s:Sender a:ActionNotSupported&lt;/wsrm:Identifier&gt;'
          +'            &lt;wsrm:MessageNumber&gt;1&lt;/wsrm:MessageNumber&gt;'
          +'        &lt;/wsrm:Sequence&gt;'
          +'        &lt;wsa:Action&gt;http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence&lt;/wsa:Action&gt;'
          +'        &lt;wsa:ReplyTo&gt;'
          +'            &lt;wsa:Address&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:Address&gt;'
          +'        &lt;/wsa:ReplyTo&gt;'
          +'        &lt;wsa:MessageID&gt;uuid:'+ MsgUid +'&lt;/wsa:MessageID&gt;'
          +'        &lt;wsa:To&gt;'+ Url +'&lt;/wsa:To&gt;'
          +'    &lt;/soap:Header&gt;'
          +'    &lt;soap:Body xmlns:wsrm="http://schemas.xmlsoap.org/ws/2005/02/rm"&gt;'
          +'        &lt;wsrm:CreateSequence&gt;'
          +'            &lt;wsrm:AcksTo xmlns:wsa="http://www.w3.org/2005/08/addressing"&gt;'
          +'                &lt;wsa:Address&gt;http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:Address&gt;'
          +'            &lt;/wsrm:AcksTo&gt;'
          +'            &lt;wsrm:Offer&gt;'
          +'                &lt;wsrm:Identifier&gt;urn:soapui:'+ SeqUid +'&lt;/wsrm:Identifier&gt;'
          +'            &lt;/wsrm:Offer&gt;'
          +'        &lt;/wsrm:CreateSequence&gt;'
          +'    &lt;/soap:Body&gt;'
          +'&lt;/soap:Envelope&gt;';
  
  $.ajax({
      type: 'POST',
      url: 'http://mywcf/service.svc', // with or without +' HTTP/1.1'
      data: soapData,
      contentType: 'application/soap+xml;charset=UTF-8',
      dataType: 'xml'
  });
  </code></pre>
  
  <p>Values in my WCF <code>web.config</code>:</p>
  
  <pre><code>&lt;system.webServer&gt;
      &lt;httpProtocol&gt;
          &lt;customHeaders&gt;
              &lt;add name="Access-Control-Allow-Origin" value="*" /&gt;
              &lt;add name="Access-Control-Allow-Methods" value="POST, OPTIONS" /&gt;
              &lt;add name="Access-Control-Allow-Headers" value="*" /&gt;
          &lt;/customHeaders&gt;
      &lt;/httpProtocol&gt;
  &lt;/system.webServer&gt;
  </code></pre>