Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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:
C#
public class Service1 : IService1
    {
        public string Sum2Integers(int n1, int n2)
        {
            int result = n1 + n2;

            return result.ToString();
        }
}


----------------------

C#
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
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 + '}';

//alert(body)

// Send the HTTP request
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/json");
xmlHttp.send(body);

// Create result handler
xmlHttp.onreadystatechange = DisplayResult
}
function DisplayResult()
{

//alert(xmlHttp.readyState)

if(xmlHttp.readyState == 4)
{
result.innerText = xmlHttp.responseText;
}
}
</script>


HTML
</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>
Posted
Updated 4-Apr-14 10:24am
v4
Comments
Do you see any errors on Developer Tool's Console Tab?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900