【发布时间】: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客户)
我错过了什么?
【问题讨论】:
-
您当前的 WCF 配置适用于
basicHttpBinding- SOAP 端点.....没有 REST 端点的配置(将使用webHttpBinding) -
你有什么好的资源来描述这两者吗?超越 MSDN?
-
去搜索吧!那里有很多好东西,例如。 dotnetspeak.com/2012/01/… 或 dotnetcurry.com/wcf/728/expose-wcf-service-soap-rest 或回复 this other SO question here