【问题标题】:Manually configuring a new WCF endpoint手动配置新的 WCF 终结点
【发布时间】:2016-01-07 04:20:52
【问题描述】:

我有一个简单的 WCF 服务:

namespace Vert.Host.VertService
{
    [ServiceContract]
    public interface IRSVP
    {
        [OperationContract]
        bool Attending();

        [OperationContract]
        bool NotAttending();
    }

    public class RSVPService : IRSVP
    {
        public RSVPService()
        {
        }

        public bool Attending()
        {
            return true;
        }

        public bool NotAttending()
        {
            return true;
        }
    }
}

我想像这样在控制台应用程序中自托管:

class Program
{
    public static void Main()
    {
        // Create a ServiceHost
        using (ServiceHost serviceHost = new ServiceHost(typeof(RSVPService)))
        {
            // Open the ServiceHost to create listeners 
            // and start listening for messages.
            serviceHost.Open();

            // The service can now be accessed.
            Console.WriteLine("The service is ready.");
            Console.WriteLine("Press <ENTER> to terminate service.");
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}

所以我正在使用这个 app.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
  </startup>
  <system.serviceModel>      
    <services>
      <service name="Vert.Host.VertService.RSVPService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/Vert" />
          </baseAddresses>
        </host>
        <endpoint
          address="/RSVP"
          binding="basicHttpBinding"
          contract="Vert.Host.VertService.IRSVP" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
        <serviceBehaviors>
            <behavior name="">
              <serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

据我了解,此设置将使我使用 http://localhost:8080/Vert/RSVP/Attending 作为有效的 REST URI,以便从任意 HTTPClient 调用,但调用无限期挂起或返回 0 No Response(我正在使用高级 REST客户)

我错过了什么?

【问题讨论】:

标签: c# wcf rest


【解决方案1】:

您的所有设置都是正确的...直到您停止输入代码并开始告诉我您拥有什么。 :)

您创建的是一个标准 WCF 服务,您可以使用服务代理或 ChannelFactory 访问它,但它会使用 SOAP 与您进行通信。

您需要this tutorial 将此 Web 服务转换为 RESTFUL 服务,返回 Json/pox。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多