簡體   English   中英

手動配置新的WCF端點

[英]Manually configuring a new WCF endpoint

我有一個簡單的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客戶端)

我想念什么?

您在所有設置中都是正確的...直到停止輸入代碼並開始告訴我您擁有什么為止。 :)

您創建的是一個標准WCF服務,您可以使用Service代理或ChannelFactory來獲取它,但是它將使用SOAP與您直接通信。

您需要本教程才能將此Web服務轉換成一個回饋Json / pox的RESTFUL服務。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM