Как настроить необходимые метаданные для WCF-службы restful?

Я пытаюсь заставить работать мой первый WCF-сервер. Но я продолжаю получать предупреждение, когда я запускаю его через VS2013. он говорит, что не может найти какие-либо метаданные службы.

Как мне это настроить?

Файл App.config выглядит следующим образом:

 <?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <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>
    <services>
      <service name="WcfJsonRestService.Service1">
        <endpoint address="http://localhost:8732/service1"

                  binding="webHttpBinding"

                  contract="WcfJsonRestService.IService1"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>


</configuration>

IService1.cs

namespace WcfJsonRestService
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        Service1.Person GetData(string id);
    }
}

Service1.cs

namespace WcfJsonRestService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Service1 : IService1
    {
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            UriTemplate = "data/{id}")]
        public Person GetData(string id)
        {
            // lookup person with the requested id 
            return new Person()
            {
                Id = Convert.ToInt32(id),
                Name = "Leo Messi"
            };
        }

        public class Person
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }
    }
}

0 ответов

Другие вопросы по тегам