Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript SOAP Request, Return String
    primarykey
    data
    text
    <p>What I'm attempting seems relatively simple, but I can't seem to find a simple answer on how to do it. I have a WCF Web Service that is self hosted. It has one function that accepts zero parameters and returns a string. All I want to do is request that method from javascript and capture that string response in javascript</p> <p>Here is the code I have, and so far it won't even return anything. I can get requests easily if I use something like SOAPUI. </p> <p><strong>App.Config</strong></p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;configSections&gt; &lt;/configSections&gt; &lt;connectionStrings&gt; &lt;add name="test.XKORE.MobileDeviceServices.Properties.Settings.ConnectionString" connectionString="Data Source=tester;Initial Catalog=test;User ID=testc;Password=testp" /&gt; &lt;/connectionStrings&gt; &lt;system.web&gt; &lt;compilation debug="true"/&gt; &lt;/system.web&gt; &lt;!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --&gt; &lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="test.XKORE.MobileDeviceServices.XKOREMobileService" behaviorConfiguration="XKOREMobileServiceBehavior"&gt; &lt;host&gt; &lt;baseAddresses&gt; &lt;add baseAddress="http://localhost:8523/test/XKORE/XKOREMobileService" /&gt; &lt;/baseAddresses&gt; &lt;/host&gt; &lt;endpoint address="" binding="basicHttpBinding" contract="test.XKORE.MobileDeviceServices.IXKOREMobileService" bindingNamespace="http://test.XKORE.MobileDeviceServices" /&gt; &lt;endpoint address="mex" binding="mexHttpBinding" contract="test.XKORE.MobileDeviceServices.IXKOREMobileService" bindingNamespace="http://test.XKORE.MobileDeviceServices" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="XKOREMobileServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="false"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;/system.serviceModel&gt; &lt;startup&gt;&lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/&gt;&lt;/startup&gt;&lt;/configuration&gt; </code></pre> <p><strong>Interface</strong></p> <pre><code>[ServiceContract] public interface IXKOREMobileService { [OperationContract] string GetChartData(); // TODO: Add your service operations here } </code></pre> <p><strong>SOAP Request</strong></p> <pre><code>&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt; &lt;s:Header&gt; &lt;Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none"&gt;http://tempuri.org/IXKOREMobileService/GetChartData&lt;/Action&gt; &lt;/s:Header&gt; &lt;s:Body&gt; &lt;GetChartData xmlns="http://tempuri.org/" /&gt; &lt;/s:Body&gt; &lt;/s:Envelope&gt; </code></pre> <p><strong>Javascript (Not Working)</strong></p> <pre><code>var response = BuildSOAPMessage('GetChartData'); alert(response); function BuildSOAPMessage (func) { var xmlhttp = new XMLHttpRequest(); xmlhttp.open("POST", "http://localhost:8523/test/XKORE/XKOREMobileService", true); var msg = ''; msg += '&lt;?xml version="1.0" encoding="utf-8"?&gt;' msg += '&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/"&gt;' msg += '&lt;soapenv:Header/&gt;' msg += '&lt;soapenv:Body&gt;' msg += '&lt;tem:' + func + '/&gt;' msg += '&lt;/soapenv:Body&gt;' msg += '&lt;/soapenv:Envelope&gt;' alert (msg); // Send the POST request xmlhttp.setRequestHeader('Content-Type', 'text/xml'); xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/IXKOREMobileService/GetJSONChartData"); xmlhttp.send(msg); return xmlhttp.responseXML; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload