REST WCF サービスを作成しました。
最初にコンソールアプリでホストしましたが、問題なく動作していました。
次に、Windows サービスでホストしました。さまざまなエラーをスローしています
以下は構成です
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="serviceMetadataBehavior">
<serviceMetadata />
</behavior>
<behavior name="restServiceMetaBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonEndpointBehavior">
<enableWebScript />
</behavior>
<behavior name="wsHttpBinding" />
</endpointBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="restServiceMetaBehavior" name="StockPriceNotifierServiceImpl.StockNotifierServiceImpl">
<!--SOAP endpoint-->
<endpoint address="net.tcp://localhost:8082/StockPriceService"
binding="netTcpBinding" bindingConfiguration="" contract="StockPriceNotifierService.IStockNotifierService" />
<endpoint address="net.tcp://localhost:8082/StockPriceService/mex" binding="mexTcpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
<!--rest endpoint-->
<endpoint address="http://localhost:8084/StockNotifierService"
binding="webHttpBinding" name="webhttp"
contract="StockPriceNotifierService.IStockNotifierRestService" />
<endpoint address="http://localhost:8084/StockNotifierService/mex"
binding="mexHttpBinding" name="MexWebHttp" contract="IMetadataExchange" />
</service>
</services>
トラブルシューティングを試みましたが、成功しませんでした。
以下は、これまでに行った手順です
初期エラー → ServiceMetadataBehavior の HttpGetEnabled プロパティは true に設定されており、HttpGetUrl プロパティは相対アドレスですが、http ベース アドレスがありません。http ベース アドレスを指定するか、HttpGetUrl を絶対アドレスに設定します。解決策 -> http://social.msdn.microsoft.com/Forums/pl/wcf/thread/2fd858cb-8988-444f-868c-2ceea9cc9705、指定された HttpGetUrl
AddressFilter 不一致エラー ->EndpointDispatcher での AddressFilter 不一致のため、To 'http://localhost:8084/StockService/MSFT/Price' を含むメッセージを受信側で処理できません。送信者と受信者の EndpointAddresses が一致していることを確認してください。解決 -> 動作追加 -> [ServiceBehavior(AddressFilterMode=AddressFilterMode.Any)]
現在、ContractFilter の不一致例外 -> System.ServiceModel.FaultException: アクション '' を含むメッセージは、EndpointDispatcher での ContractFilter の不一致により、受信者で処理できません。
いくつかの基本が欠けているようですが、これまでのところ手がかりはありません。
契約
[ServiceContract] //REST
public interface IStockNotifierRestService
{
[OperationContract]
[WebGet(UriTemplate = Routing.GetCurrentPriceRoute,
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Xml,
ResponseFormat = WebMessageFormat.Json
)]
double GetCurrentPrice(string symbol);
[ServiceContract] //SOAP
public interface IStockNotifierService:IStockNotifierRestService
{
[OperationContract]
double GetPrice(String symbolname, DateTime timestamp);
}
実装
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Reentrant,
InstanceContextMode= InstanceContextMode.Single, AddressFilterMode=AddressFilterMode.Any)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class StockNotifierServiceImpl:IStockNotifierService
{
public double GetPrice(string symbolname, DateTime timestamp)
{
return 12.0;
}
public double GetCurrentPrice(string symbolname)
{
return 13.0;
}
}