I'm unable to hit the WCF service which is hosted on a one server; the html page is working on computer fine but not on Android
WCF code:
public class Service1 : IService1
{
public string Sum2Integers(int n1, int n2)
{
int result = n1 + n2;
return result.ToString();
}
}
----------------------
public interface IService1
{
[OperationContract]
string Sum2Integers(int n1, int n2);
}
--------------------------
<configuration>
<appsettings>
<connectionstrings>
<system.web>
<compilation debug="true" targetframework="4.0">
<authentication mode="Windows">
<pages controlrenderingcompatibilityversion="3.5" clientidmode="AutoID">
<system.web.extensions>
<scripting>
<webservices>
</scripting>
<system.servicemodel>
<bindings>
<webhttpbinding>
<binding name="AjaxBinding">
<services>
<service name="Wcf2Ajax.Service1" behaviorconfiguration="Wcf2Ajax.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="ajaxEndpoint" behaviorconfiguration="AjaxBehavior" binding="webHttpBinding" bindingconfiguration="AjaxBinding" contract="Wcf2Ajax.IService1">
<identity>
<dns value="localhost">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange">
<behaviors>
<endpointbehaviors>
<behavior name="AjaxBehavior">
<enablewebscript>
<servicebehaviors>
<behavior name="Wcf2Ajax.Service1Behavior">
<servicemetadata httpgetenabled="true">
<servicedebug includeexceptiondetailinfaults="false">
---------------------------------------------
HTML which runs on android:
HTML which runs on android:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script type="text/javascript">
var xmlHttp = new ActiveXObject("Microsoft.XmlHttp");
function CallWcfAjax()
{
var url = "http://localhost:56966/Service1.svc/ajaxEndpoint/";
url = url + "Sum2Integers";
var body = '{"n1":';
body = body + document.getElementById("num1").value + ',"n2":';
body = body + document.getElementById("num2").value + '}';
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send(body);
xmlHttp.onreadystatechange = DisplayResult
}
function DisplayResult()
{
if(xmlHttp.readyState == 4)
{
result.innerText = xmlHttp.responseText;
}
}
</script>
</head>
<body>
<input type="text" id="num1" />
<input type="text" id="num2" />
<input type="button" önclick="CallWcfAjax()" value="Call WCF via AJAX" />
Result is
</body>
</html>