c# - The OperationContractAttribute declared on method 'method' in type 'service' is invalid. in wcf -


i trying make wcf service in visual studio can see here:

[servicecontract]     public interface ireportsrc{             [operationcontract]         list<tblarticle> returnarticlelist();          [operationcontract]        int returnarticlelistcount();           [operationcontract]         list<tblpayment> returnpaymentlist();           [operationcontract]          int returnpaymentsum();           [operationcontract]         list<tblnew> returnnews();           [operationcontract]         list<tbluserinfo> returnusers();           [operationcontract]         int returnuserscount();           [operationcontract]         list<tbluserinfo> returnreviewers();           [operationcontract]         list<tblsponsor> returnssponser();      } 

so implement interface can see in service :

[aspnetcompatibilityrequirements(         requirementsmode = aspnetcompatibilityrequirementsmode.allowed)]     public class reportsrc : ireportsrc     {         dblinqtodb.dbdatacontext db=new dbdatacontext();           list<tblarticle> ireportsrc.returnarticlelist()         {             return db.tblarticles.tolist();         }          public list<tblpayment> returnpaymentlist()         {             return db.tblpayments.tolist();         }          public list<tblnew> returnnews()         {             return db.tblnews.tolist();         }         [operationcontract(isoneway = true)]         public list<tbluserinfo> returnusers()         {             return db.tbluserinfos.tolist();         }          public list<tbluserinfo> returnreviewers()         {             list<tbluserinfo> res =                 (from in db.tbluserinfos                  join b in db.tbluserlogins on i.username equals b.username                  b.isjuror == "1"                  select i).tolist();             return res;          }          public list<tblsponsor> returnssponser()         {             return db.tblsponsors.tolist();          }           public int returnarticlelistcount()         {             return db.tblarticles.count();         }          public int returnpaymentsum()         {             return db.tblpayments.sum(i => int.parse(i.price));         }          public int returnuserscount()         {             return db.tbluserinfos.count();         }     } 

so call service in local computer http://localhost:2432/services/reportsrc.svc ,but when call service error :

the operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'. 

when run service visual wizard:

error: cannot obtain metadata http://localhost:2432/services/reportsrc.svc if windows (r) communication foundation service have access, please check have enabled metadata publishing @ specified address.  enabling metadata publishing, please refer msdn documentation @ http://go.microsoft.com/fwlink/?linkid=65455.ws-metadata exchange error    uri: http://localhost:2432/services/reportsrc.svc    metadata contains reference cannot resolved: 'http://localhost:2432/services/reportsrc.svc'.    requested service, 'http://localhost:2432/services/reportsrc.svc' not activated. see server's diagnostic trace logs more information.http error    uri: http://localhost:2432/services/reportsrc.svc    there error downloading 'http://localhost:2432/services/reportsrc.svc'.    request failed error message:--<!doctype html><html>    <head>        <title>the operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'.</title>        <meta name="viewport" content="width=device-width" />        <style>         body {font-family:"verdana";font-weight:normal;font-size: .7em;color:black;}          p {font-family:"verdana";font-weight:normal;color:black;margin-top: -5px}         b {font-family:"verdana";font-weight:bold;color:black;margin-top: -5px}         h1 { font-family:"verdana";font-weight:normal;font-size:18pt;color:red }         h2 { font-family:"verdana";font-weight:normal;font-size:14pt;color:maroon }         pre {font-family:"consolas","lucida console",monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}         .marker {font-weight: bold; color: black;text-decoration: none;}         .version {color: gray;}         .error {margin-bottom: 10px;}         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }         @media screen , (max-width: 639px) {          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }         }         @media screen , (max-width: 479px) {          pre { width: 280px; }         }        </style>    </head>    <body bgcolor="white">            <span><h1>server error in '/' application.<hr width=100% size=1 color=silver></h1>            <h2> <i>the operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'.</i> </h2></span>            <font face="arial, helvetica, geneva, sunsans-regular, sans-serif ">            <b> description: </b>an unhandled exception occurred during execution of current web request. please review stack trace more information error , originated in code.            <br><br>            <b> exception details: </b>system.invalidoperationexception: operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'.<br><br>            <b>source error:</b> <br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code>an unhandled exception generated during execution of current web request. information regarding origin , location of exception can identified using exception stack trace below.</code>                  </td>               </tr>            </table>            <br>            <b>stack trace:</b> <br><br>            <table width=100% bgcolor="#ffffcc">               <tr>                  <td>                      <code><pre>[invalidoperationexception: operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'.]   system.servicemodel.description.servicereflector.getinterfaces(type service) +471   system.servicemodel.servicehost.createdescription(idictionary`2& implementedcontracts) +248   system.servicemodel.servicehostbase.initializedescription(urischemekeyedcollection baseaddresses) +146   system.servicemodel.servicehost.initializedescription(type servicetype, urischemekeyedcollection baseaddresses) +46   system.servicemodel.servicehost..ctor(type servicetype, uri[] baseaddresses) +146   system.servicemodel.activation.servicehostfactory.createservicehost(type servicetype, uri[] baseaddresses) +30   system.servicemodel.activation.servicehostfactory.createservicehost(string constructorstring, uri[] baseaddresses) +494   system.servicemodel.hostingmanager.createservice(string normalizedvirtualpath, eventtraceactivity eventtraceactivity) +1434   system.servicemodel.hostingmanager.activateservice(serviceactivationinfo serviceactivationinfo, eventtraceactivity eventtraceactivity) +52   system.servicemodel.hostingmanager.ensureserviceavailable(string normalizedvirtualpath, eventtraceactivity eventtraceactivity) +598[serviceactivationexception: service '/services/reportsrc.svc' cannot activated due exception during compilation.  exception message is: operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'..]   system.runtime.asyncresult.end(iasyncresult result) +489276   system.servicemodel.servicehostingenvironment.ensureserviceavailablefast(string relativevirtualpath, eventtraceactivity eventtraceactivity) +73   system.servicemodel.activation.hostedhttprequestasyncresult.handlerequest() +461   system.servicemodel.activation.hostedhttprequestasyncresult.end(iasyncresult result) +178   system.servicemodel.activation.servicehttphandler.endprocessrequest(iasyncresult result) +6   system.web.callhandlerexecutionstep.onasynchandlercompletion(iasyncresult ar) +129</pre></code>                  </td>               </tr>            </table>            <br>            <hr width=100% size=1 color=silver>            <b>version information:</b>ÿmicrosoft .net framework version:4.0.30319; asp.net version:4.0.30319.34280            </font>    </body></html><!-- [invalidoperationexception]: operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'.   @ system.servicemodel.description.servicereflector.getinterfaces(type service)   @ system.servicemodel.servicehost.createdescription(idictionary`2& implementedcontracts)   @ system.servicemodel.servicehostbase.initializedescription(urischemekeyedcollection baseaddresses)   @ system.servicemodel.servicehost.initializedescription(type servicetype, urischemekeyedcollection baseaddresses)   @ system.servicemodel.servicehost..ctor(type servicetype, uri[] baseaddresses)   @ system.servicemodel.activation.servicehostfactory.createservicehost(type servicetype, uri[] baseaddresses)   @ system.servicemodel.activation.servicehostfactory.createservicehost(string constructorstring, uri[] baseaddresses)   @ system.servicemodel.servicehostingenvironment.hostingmanager.createservice(string normalizedvirtualpath, eventtraceactivity eventtraceactivity)   @ system.servicemodel.servicehostingenvironment.hostingmanager.activateservice(serviceactivationinfo serviceactivationinfo, eventtraceactivity eventtraceactivity)   @ system.servicemodel.servicehostingenvironment.hostingmanager.ensureserviceavailable(string normalizedvirtualpath, eventtraceactivity eventtraceactivity)[serviceactivationexception]: service '/services/reportsrc.svc' cannot activated due exception during compilation.  exception message is: operationcontractattribute declared on method 'returnusers' in type 'accidentcongress.services.reportsrc' invalid. operationcontractattributes valid on methods declared in type has servicecontractattribute. either add servicecontractattribute type 'accidentcongress.services.reportsrc' or remove operationcontractattribute method 'returnusers'..   @ system.runtime.asyncresult.end[tasyncresult](iasyncresult result)   @ system.servicemodel.servicehostingenvironment.ensureserviceavailablefast(string relativevirtualpath, eventtraceactivity eventtraceactivity)   @ system.servicemodel.activation.hostedhttprequestasyncresult.handlerequest()   @ system.servicemodel.activation.hostedhttprequestasyncresult.end(iasyncresult result)   @ system.servicemodel.activation.servicehttphandlerfactory.servicehttphandler.endprocessrequest(iasyncresult result)   @ system.web.httpapplication.callhandlerexecutionstep.onasynchandlercompletion(iasyncresult ar)-->--. 

why want specify operation contract in implementation class? can specify in interface 1 way attribute below , work fine.

[operationcontract(isoneway=true)] list<tbluserinfo> returnusers(); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -