手动配置新的 WCF 端点 [英] Manually configuring a new WCF endpoint

查看:25
本文介绍了手动配置新的 WCF 端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 WCF 服务:

I have a simple WCF service:

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;
        }
    }
}

我想在控制台应用程序中自托管,如下所示:

I'd like to self-host in a console application like so:

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

So I'm using this 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 客户端)

As I understand it, this setup would leave me with http://localhost:8080/Vert/RSVP/Attending as a valid REST URI to call from an arbitrary HTTPClient, but the call is hanging indefinitely or coming back with a 0 No Response (I'm using Advanced REST client)

我错过了什么?

推荐答案

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

You are RIGHT in all of your setup...right up to the point where you stopped typing code and started telling me what you have. :)

您创建的是标准 WCF 服务,您可以使用服务代理或 ChannelFactory 访问它,但它将使用 SOAP 按原样与您通信.

What you've created is a std WCF service and you can get to it using a Service proxy or a ChannelFactory, but it will communicate with you as-is using SOAP.

您需要 本教程将该网络服务转变为返回 Json/pox 的 RESTFUL 服务.

You need this tutorial to turn this webservice into a RESTFUL service giving back Json/pox.

这篇关于手动配置新的 WCF 端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆