Skip to content Skip to sidebar Skip to footer

Unable To Post Data To Wcf From Android

I'm trying to send data to WCF service from an Android Application but somehow the service doesn't seems to be call through the android. I received a STATUSCODE value = 500 through

Solution 1:

The problem is your host name doesn't match what you are using from the phone.

You can turn off address filter to fix this temporarily:

[ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]
publicclassService1 : IService1
{
    ....
}

But you should fix the hostname when you release to production

Solution 2:

Create a domain in your machine with proper port number and make sure you are able to call the service using the Google's Rest client.If it works,then you won't find any issue if you call the same using your android phone.

Following article will help to setup virtual directory with proper port number.[http://www.hosting.com/support/iis7/create-new-sites-in-iis-7/]

Note you can't call localhost directly from your mobile.atleast try to call the service with ipaddress.[http://localhost/service/mycar] =>[http://DemoService/service/mycar]

Solution 3:

The following code will help you to debug your code a little bit deep.

catch (Exception ex)
            {
                WebException webexception = (WebException)ex;
                var responseresult = webexception.Response as HttpWebResponse;

                //Code to debug Http Responsevar responseStream = webexception.Response.GetResponseStream();
                string fault_message = string.Empty;
                int lastNum = 0;
                do
                {
                    lastNum = responseStream.ReadByte();
                    fault_message += (char)lastNum;
                } while (lastNum != -1);
                responseStream.Close();
}

Solution 4:

Never mind, I have made several changes in web.config file and got the solution. <endpointBehaviors>tag was missing in my case and several other things. here is the updated code of web.config file.

[UPDATED web.config file]

<?xml version="1.0"?><configuration><appSettings/><connectionStrings><addname="DB"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Munyb\Documents\Visual Studio 2010\Projects\CarSercive\CarSercive\App_Data\Database1.mdf;Integrated Security=True;User Instance=True"providerName="System.Data.SqlClient"/></connectionStrings><system.web><compilationdebug="true"targetFramework="4.0"></compilation><authenticationmode="Windows"/><pagescontrolRenderingCompatibilityVersion="3.5"clientIDMode="AutoID"/></system.web><system.serviceModel><services><servicename="CarSercive.Service1"behaviorConfiguration="RESTfulServ"><!-- Service Endpoints --><endpointaddress=""binding="webHttpBinding"contract="CarSercive.IService1"behaviorConfiguration="web"></endpoint></service></services><behaviors><endpointBehaviors><behaviorname="web"><webHttp/></behavior></endpointBehaviors><serviceBehaviors><behaviorname="RESTfulServ"><serviceMetadatahttpGetEnabled="true"/><serviceDebugincludeExceptionDetailInFaults="false"/></behavior></serviceBehaviors></behaviors><serviceHostingEnvironmentmultipleSiteBindingsEnabled="true"></serviceHostingEnvironment></system.serviceModel><system.webServer><modulesrunAllManagedModulesForAllRequests="true"></modules></system.webServer></configuration>

Post a Comment for "Unable To Post Data To Wcf From Android"