Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript + SOAP + WCF works on Visual Studio 2010 but not on Visual Studio 2008
    primarykey
    data
    text
    <p>I have the following code which works in a Visual Studio 2010 WCF project.<br> However when I recreated the project in Visual Studio 2008, it did not worked and only gave me the following error StatuesText "Unsupported Media Type".<br> <strong>Edit:</strong><br> What i figured out is that the problem is in the Web.config file since it is different between Visual Studio 2010 project and 2008 project. Therefore I've added the all Web.config to the Question.</p> <p>The javascript which calling the WCF service using soap is the following : </p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" &gt; &lt;head&gt; &lt;title&gt;Untitled Page&lt;/title&gt; &lt;script type="text/javascript" src="jQuery/jquery-1.3.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jQuery/jquery.xml2json.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jQuery/json2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function MyRequest() { debugger; var methodName = "GetData" var responseTagName = methodName + "Response"; var resultTagName = methodName + "Result"; var sendData = ""; sendData += '&lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;'; sendData += ' &lt;s:Body&gt;'; sendData += ' &lt;' + methodName + ' xmlns="http://tempuri.org/"&gt;'; sendData += ' &lt;name&gt;Shlomy&lt;/name&gt;'; sendData += ' &lt;/' + methodName + '&gt;'; sendData += ' &lt;/s:Body&gt;'; sendData += '&lt;/s:Envelope&gt;'; var response = $.ajax({ type: "POST", contentType: "text/xml; charset=utf-8", methodName: methodName, url: "http://localhost:16109/Service1.svc", data: sendData, async: false, beforeSend: function (req, methodName) { var soapActionURI = "http://tempuri.org/IService1/GetData"; req.setRequestHeader("SOAPAction", soapActionURI); }, success: function (xml, type, xhr) { var result = $(xml).find(resultTagName); var resultjson = $.xml2json(result); successHandler(xml.text); }, error: function (xmlHttpRequest, textStatus, errorThrown) { alert(xmlHttpRequest.responseText); } }); } function successHandler(soapResult) { alert(soapResult); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="button" onclick="MyRequest()" value="Call WCF via AJAX" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And the WCF Service(HelloWorldWCFService) is the following:<br> Service1.svc: </p> <pre><code>&lt;%@ ServiceHost Language="C#" Debug="true" Service="HelloWorldWCFServiceLibrary.Service1" %&gt; &lt;%@ Assembly Name="HelloWorldWCFServiceLibrary" %&gt; </code></pre> <p>WCF Web.Config: </p> <pre><code> &lt;?xml version="1.0"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.0" /&gt; &lt;/system.web&gt; &lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="debug"&gt; &lt;!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;!-- 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 --&gt; &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;/behaviors&gt; &lt;services&gt; &lt;service name="HelloWorldWCFServiceLibrary.Service1" behaviorConfiguration="debug" &gt; &lt;endpoint address="mex" binding="wsHttpBinding" contract="HelloWorldWCFServiceLibrary.IService1" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests="true"/&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p>And the WCF Library(HelloWorldWCFServiceLibrary) is the following:<br> IService.cs: </p> <pre><code> // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together. [ServiceContract] public interface IService1 { [OperationContract] CompositeType GetDataUsingDataContract(CompositeType composite); // TODO: Add your service operations here [OperationContract] string GetData(string name); } </code></pre> <p>Service1.cs:</p> <pre><code>public class Service1 : IService1 { public string GetData(string name) { return "WCFSoapTest"; } } </code></pre> <p>I've tried for several days figuring out what is the difference between the 2008 solution and the 2010 and why only the 2010 project works. but to no avail. any suggestions ?</p> <p>Thanks.</p>
    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.
 

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