c# - "unreachable code detected" when in a WCF service -
this question directly related this question figured because subject matter different start new question current issue. have wcf service service, , gui. gui passes int wcf supposed stow list<int> intlist
; in service want access list. issue when attempt add list in wcf service recieve "unreachable code detected" warning, , adding line skipped when go debug through it. how can list 'reachable' ?
below wcf code, gui call wcf, , service using list<>
wcf:
wcf:
[servicecontract(namespace = "http://calcraservice")] public interface icalculator { [operationcontract] int add(int n1, int n2); [operationcontract] list<int> getallnumbers(); } // implement icalculator service contract in service class. public class calculatorservice : icalculator { public list<int> m_myvalues = new list<int>(); // implement icalculator methods. public int add(int n1,int n2) { int result = n1 + n2; return result; m_myvalues.add(result); } public list<int> getallnumbers() { return m_myvalues; } }
gui:
private void button1_click(object sender, eventargs e) { using (channelfactory<icalculator> factory = new channelfactory<icalculator>(new netnamedpipebinding(), new endpointaddress("net.pipe://localhost/myserviceaddress"))) { icalculator proxy = factory.createchannel(); int trouble = proxy.add((int)nud.value,(int)nud.value); } }
service:
protected override void onstart(string[] args) { if (mhost != null) { mhost.close(); } mhost = new servicehost(typeof(calculatorservice), new uri("net.pipe://localhost")); mhost.addserviceendpoint(typeof(icalculator), new netnamedpipebinding(), "myserviceaddress"); mhost.open(); using (channelfactory<icalculator> factory = new channelfactory<icalculator>(new netnamedpipebinding(), new endpointaddress("net.pipe://localhost/myserviceaddress"))) { icalculator proxy = factory.createchannel(); biglist.addrange(proxy.getallnumbers()); } }
so have:
int result = n1 + n2; return result; // <-- return statement m_myvalues.add(result); // <-- code can never reached!
since m_myvalues.add()
doesn't alter state of result
in way, why not flip lines:
int result = n1 + n2; m_myvalues.add(result); return result;
Comments
Post a Comment