I created a WCF service that retrieves data from an SQL database and can update and modify data in an SQL database. I am trying to call WCF methods from xamarin for android and xamarin for iOS. I searched alot for an example of how to call the PUT and POST method from the WCF service via xamarin for android and xamarin for iOS, but no luck. I added the WCF code below for reference .... even the web API created, but all the examples and guides for using the web API are ways to call the GET method. I do not see any help document that shows how to call the PUT or Post method from WCF or Web api through the cross-platform. I tested the WCF service through Fiddler and worked fine. What will be the next step. I created a proxy for this web service using SlsvcUtil.exe, as indicated in the xamarin documentation. Can someone send one example of xamarin.Android, which will call the update or delete method from below the wcf.Desperately service is looking for help.Service contains the webHttp binding.
FOS
Service1.svc.cs
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; public class Service1 : IService1 { public List GetDeptsList() { using (DeptDBEntities entities = new DeptDBEntities()) { return entities.Depts.ToList(); } } public Dept GetDeptByID(string no) { try { int deptId = Convert.ToInt32(no); using (DeptDBEntities entities = new DeptDBEntities()) { return entities.Depts.SingleOrDefault(dept => dept.no == deptId); } } catch { throw new FaultException("Something went wrong"); } } public void AddDept(string name) { using (DeptDBEntities entities = new DeptDBEntities()) { Dept dept = new Dept { name = name }; entities.Depts.Add(dept); entities.SaveChanges(); } } public void UpdateDept(string no, string name) { try { int deptId = Convert.ToInt32(no); using (DeptDBEntities entities = new DeptDBEntities()) { Dept dept = entities.Depts.SingleOrDefault(b => b.no == deptId); dept.name = name; entities.SaveChanges(); } } catch(Exception e) { throw new FaultException(e.Message); } } public void DeleteDept(string no) { try { int deptId = Convert.ToInt32(no); using (DeptAppDBEntities entities = new DeptAppDBEntities()) { Dept dept = entities.Depts.SingleOrDefault(b => b.no == deptId); entities.Depts.Remove(dept); entities.SaveChanges(); } } catch { throw new FaultException("Something went wrong"); } } }
web.config
<?xml version="1.0"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/> </configSections> <system.web> <compilation debug="true" targetFramework="4.0"> <assemblies> <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> </assemblies> </compilation> <pages controlRenderingCompatibilityVersion="4.0"/> </system.web> <system.serviceModel> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <services> <service name="WcfWithJsonP.Service1" behaviorConfiguration="restfulBehavior"> <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" bindingConfiguration="" contract="WcfWithJsonP.IService1"/> <host> <baseAddresses> <add baseAddress="http://localhost/Service1"/> </baseAddresses> </host> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="webBehavior"> <webHttp defaultOutgoingResponseFormat="Json"/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="restfulBehavior"> <serviceMetadata httpGetEnabled="true"/> <serviceDebug includeExceptionDetailInFaults="false"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> <directoryBrowse enabled="true"/> </system.webServer> <entityFramework> <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> <parameters> <parameter value="v12.0"/> </parameters> </defaultConnectionFactory> </entityFramework> </configuration
<P →
Main.axml for
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minWidth="25px" android:minHeight="25px"> <LinearLayout android:orientation="vertical" android:layout_width="134.1dp" android:layout_height="fill_parent" android:minWidth="25px" android:minHeight="25px"> <TextView android:text="Enter No:" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="163.4dp" android:layout_height="wrap_content" android:id="@+id/No" android:layout_marginBottom="27.5dp" android:layout_marginTop="0.0dp" android:layout_marginLeft="5dp" /> <TextView android:text="Enter name:" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="252.7dp" android:layout_height="wrap_content" android:id="@+id/Name" android:layout_marginBottom="27.5dp" android:layout_marginTop="0.0dp" android:layout_marginLeft="5dp" android:enabled="false" android:visibility="invisible" /> </LinearLayout> <Button android:id="@+id/Get" android:layout_width="fill_parent" android:layout_height="36.6dp" android:text="Get" /> <Button android:id="@+id/ADD" android:layout_width="fill_parent" android:layout_height="36.6dp" android:text="ADD" /> <Button android:id="@+id/Update" android:layout_width="fill_parent" android:layout_height="36.6dp" android:text="Update" /> <Button android:id="@+id/Delete" android:layout_width="fill_parent" android:layout_height="36.6dp" android:text="Delete" /> <TextView android:text="" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/ValueNo" android:layout_marginBottom="27.5dp" android:layout_marginTop="0.0dp" android:background="@android:color/holo_purple" /> <TextView android:text="" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/ValueName" android:layout_marginBottom="27.5dp" android:layout_marginTop="0.0dp" android:background="@android:color/holo_purple" /> </LinearLayout>
source share