WCF/WF - Failed to invoke the service. Possible causes: The service is offline or inacces

Asked By skumari woonna on 21-May-10 06:54 AM
Earn up to 50 extra points for answering this tough question.
I did 1 function in wcf using linq to sql.the code
public IEnumerable<MMetric> GetSearchresults(string UID, string Aame, string Mname)
{

ADataContext db = new ADataContext();



IEnumerable<MoMetric> getdata = (from p in db.MMetrics
where p.MID == MID && p.AID == AID
select new MoMetric { DoUId = p.DUId, AID = p.AID, MID = p.MID, EntryDate = p.EntryDate }).AsEnumerable();
return getdata();
iam getting the following error:-
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
in app.con file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
  </configSections>
  <connectionStrings>
    <add name="ApService.Properties.Settings.ApConnectionString"
      connectionString="Data Source=mdw2;Initial Catalog=Ap;Integrated Security=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="NewBinding0" maxReceivedMessageSize="9999999">
          <readerQuotas maxDepth="124" maxStringContentLength="9999999"
            maxArrayLength="124" maxBytesPerRead="9999999" maxNameTableCharCount="99999" />
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ApService.AppServiceBehavior"
        name="ApService.ApService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
          name="ApService" contract="ApService.IAService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8731/ApService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ApService.ApServiceBehavior">

how to solve this problem.
plz help me its very urgent


[)ia6l0 iii replied to skumari woonna on 14-Apr-12 06:17 AM
The config looks okay, however the easiest way to fix such issues is to place a try-catch around the linq code and check the error. 

public IEnumerable<MMetric> GetSearchresults(string UID, string Aame, string Mname)
{
 try
 {
   ADataContext db = new ADataContext();
   IEnumerable<MoMetric> getdata = (from p in db.MMetrics 
     where p.MID == MID && p.AID == AID
     select new MoMetric { DoUId = p.DUId, AID = p.AID, MID = p.MID, EntryDate = p.EntryDate }).AsEnumerable();
}
catch(Exception ex)
{
   
//ex
}
finally
{
  return getdata();
}
}


Hope this helps.