この例に従って動作させようとしています: 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
たとえば を使用して) 接続しようとすると、「接続が拒否されました」というエラーが返されることです。ご覧のとおり、コントラクト クラスとサービスの実装に間違った名前を付けようとしましたが、例外はありませんでした。私は何を間違っていますか?