c# - Compact Framework communication with WCF without NETCFSvcUtil generated proxies -
c# - Compact Framework communication with WCF without NETCFSvcUtil generated proxies -
is possible communicate wcf service without using netcfsvcutil generate proxy?
i'm trying phone call wcf service on mobile using compact framework. i not want utilize netcfsvcutil generate proxy particular reason.
i have sample code on mobile side test out :
// contract defined @ client side (mobile device) public interface iservice1 { string getdata(int value); } public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { seek { string address = "http://192.168.30.88:8731/design_time_addresses/wcfservicelibrary1/service1/"; // throws here .... var channelfactory = createdefaultbinding().buildchannelfactory<iservice1>(new system.servicemodel.channels.bindingparametercollection()); var channel = channelfactory.createchannel(new endpointaddress(new uri(address))); var result = channel.getdata(5); this.text = result.tostring(); } grab (exception ex) { messagebox.show(ex.tostring()); } } public static system.servicemodel.channels.binding createdefaultbinding() { system.servicemodel.channels.custombinding binding = new system.servicemodel.channels.custombinding(); binding.elements.add(new system.servicemodel.channels.textmessageencodingbindingelement(system.servicemodel.channels.messageversion.soap11, system.text.encoding.utf8)); binding.elements.add(new system.servicemodel.channels.httptransportbindingelement()); homecoming binding; } }
but i'm getting exception : channel type 'callingwcffromdevice.iservice1' requested, binding 'custombinding' doesn't back upwards or isn't configured back upwards it. parameter name: tchannel
any clue going on? i'm guessing i'm not using buildchannelfactory correctly ...
i'm not sure requirements have security might simpler utilize 1 of pre-defined bindings such basichttpbinding; create code following:
iservice1 channel = null; seek { basichttpbinding binding = new basichttpbinding(); endpointaddress address = new endpointaddress("http://192.168.30.88:8731/design_time_addresses/wcfservicelibrary1/service1/"); ichannelfactory<iservice1> mill = binding.buildchannelfactory<iservice1>(new bindingparametercollection()); channel = factory.createchannel(address); // utilize channel here... } { if(channel != null && ((icommunicationobject)channel).state == communicationstate.opened) { ((icommunicationobject)channel).close(); } }
in definition of iservice1 not include of attributes necessary, interface needs servicecontractattribute applied it, , method in interface needs operationcontractattribute applied so:
[servicecontract] public interface iservice1 { [operationcontract] string getdata(int value); }
c# .net wcf compact-framework
Comments
Post a Comment