WCF with SQL table - exposing metadata

Go To StackoverFlow.com

0

I developed small WCF service which takes all records from table. It looks like that:

IService1.cs:

[ServiceContract]
public interface IService1
{
    List<badanieCis> GetRecords();
}

Service1.svc.cs:

public List<badanieCis> GetRecords()
{
   przychodniaEntities dataContext = new przychodniaEntities();
   return dataContext.badanieCis.ToList();
}

And I am getting a message: Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata

What I have made after some research was changing markup in svc file for this one:

<%@ ServiceHost Language="C#" Debug="true"
    Service="Harvesting.Service.HarvestingService" CodeBehind="Service1.svc.cs" %>

But still nothing.

My web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
    <add name="przychodniaEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DAREK-PC\SQLExpress;initial catalog=przychodnia;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>
2012-04-04 08:25
by dargod
where are you hosting it? IIS? Where is your config - Aliostad 2012-04-04 08:27
just testing on development server, I have added confi - dargod 2012-04-04 08:32


0

You are missing service definition in the config file. You need something like:

<services>
  <service behaviorConfiguration="..." name="Service1 with namespace">
    <endpoint address="..." name="..." binding="wsHttpBinding" bindingConfiguration="...." contract="IService1 with unterface" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
 <services>
 ...

You may use this tool to help with config.

2012-04-04 08:38
by Aliostad
I must say that I am pretty new to WFC. Can you tell me what should I put instead "..." and where exactly insert this code in Web.config - dargod 2012-04-04 08:42
I can point you in the right direction but cannot do your work for you. If you are using WCF you need to learn a lot - a steep learning curve so you had better read a bit on WCF configuration - Aliostad 2012-04-04 08:48
I understand, thank you for the link. Unfortunately I can't find that tool in my SDK. Now I need to google about i - dargod 2012-04-04 08:50
Ok, I ran the tool from VS Tools menu. I will make some updates if it won't go well : - dargod 2012-04-04 08:55
Ads