c# - How to fill DataGridView on wcf callback operation -
i have tried fill datagridview using wcf callback operation on button click on first click wcf returns null value & when click button second time fetch data & fill gridview data.
below wcf service....
[servicecontract(sessionmode = sessionmode.required, callbackcontract =typeof(iservicecallback))] public interface iservice { [operationcontract(isoneway=true)] void getdata(string username,string password); } /// <summary> /// callback interface /// </summary> public interface iservicecallback { [operationcontract(isoneway=true)] void sendresult(department[] arrdept); } [datacontract] public class department { [datamember] public int deptno { get; set; } [datamember] public string deptname { get; set; } [datamember] public int capacity { get; set; } } [servicebehavior(instancecontextmode=instancecontextmode.persession)] public class service : iservice { /// <summary> /// channel instance used called current operation /// </summary> public iservicecallback callback { { return operationcontext.current.getcallbackchannel<iservicecallback>(); } } public void getdata(string username, string password) { department[] arrdept = new department[] { new department() {deptno=10,deptname="it",capacity=4500}, new department() {deptno=20,deptname="hrd",capacity=200}, new department() {deptno=30,deptname="accts",capacity=40} }; if (username.trim() == "mahesh" && password == "mahesh") { thread.sleep(10000); callback.sendresult(arrdept); } } } web.config
<system.servicemodel> <services> <service behaviorconfiguration="service" name="wcf_callback_service.service"> <endpoint address="" binding="wsdualhttpbinding" contract="wcf_callback_service.iservice"> </endpoint> <endpoint address="mex" binding="mexhttpbinding" contract="imetadataexchange" /> </service> </services> <behaviors> <servicebehaviors> <behavior name="service"> <servicemetadata httpgetenabled="true"/> <servicedebug includeexceptiondetailinfaults="false"/> </behavior> </servicebehaviors> </behaviors> </system.servicemodel> client call...
public class requestcallback : iservicecallback { private department[] _departments; public department[] departments { { return _departments; } set { _departments = value; } } public void sendresult(department[] arrdept) { departments = arrdept; messagebox.show("response received " + departments.count().tostring() ); } } public partial class form1 : form { myref.serviceclient proxy; requestcallback callback; public form1() { initializecomponent(); } private void btngetdata_click(object sender, eventargs e) { proxy.getdata("mahesh", "mahesh"); messagebox.show("values send service"); dgvdept.datasource = callback.departments; } private void form1_load(object sender, eventargs e) { callback = new requestcallback(); //get instancecontext of callback contract class instancecontext context = new instancecontext(callback); proxy = new myref.serviceclient(context); } } client app.config..
<configuration> <system.servicemodel> <bindings> <wsdualhttpbinding> <binding name="wsdualhttpbinding_iservice" /> </wsdualhttpbinding> </bindings> <client> <endpoint address="http://localhost:4221/service.svc" binding="wsdualhttpbinding" bindingconfiguration="wsdualhttpbinding_iservice" contract="myref.iservice" name="wsdualhttpbinding_iservice"> <identity> <userprincipalname value="my-pc\my pc" /> </identity> </endpoint> </client> </system.servicemodel> </configuration>
i'm guessing you're looking few lines of code make magically work, don't think you'll find that. can tell how use wcf update datagridview.
so have controller program grid exists, , grid used display status of set of emulators load test software. when start controller , load test, follows:
the controller uses wcf call (wshttpbinding) call start() route on emulator, has return value of object
public void start(iprogress<emulatorstatus> progress) { } on emulator side, every time routine finished emulator, uses progress.report(emulatorstatus) send controller object (containing text, numbers, booleans) describing status of emulation.
on client side, controller looping every 10 seconds, checking status updates emulator host.
while ((this.m_doheartbeatloop)) { //update grid if (statuschange) { datagridview.datasource = new list<emulatorstatus>(); } //sleep between each watchdog loop thread.sleep(10000); } i'm not sure if that's you're looking for, it's i'm using. best of luck.
Comments
Post a Comment