尝试按照此示例使其工作:http ://weblogs.asp.net/kiyoshi/archive/2008/10/08/wcf-using-webhttpbinding-for-rest-services.aspx
这是我的App.config
:
<system.serviceModel>
<services>
<!-- The service for the TEST WEB client -->
<service name="MyServer.AAServiceType" behaviorConfiguration="Default">
<endpoint address="testservice"
binding="webHttpBinding" behaviorConfiguration="webBehavior"
contract="MyServer.AAIContractName" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8787/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<!-- TEST WEB BEHAVIOR -->
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<!-- TEST WEB ENDPOINT -->
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
更新:服务合同是:
namespace MyServer
{
[ServiceContract(SessionMode=SessionMode.NotAllowed)]
public interface IContractName
{
[WebGet(UriTemplate = "date/{year}/{month}/{day}", ResponseFormat = WebMessageFormat.Xml)]
[OperationContract]
string GetDate(string day, string month, string year);
}
public class ServiceType : IContractName
{
public string GetDate(string day, string month, string year)
{
return new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)).ToString("dddd, MMMM dd, yyyy");
}
}
}
问题是,当我尝试连接到 8787 端口(putty
例如使用 )时,会返回“连接被拒绝”错误。如您所见,我还尝试在合同类和服务实现中输入错误的名称,并且没有出现异常。请问我做错了什么?