我创建了一个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>
我试图解决,但没有成功。
以下是迄今所采取的步骤
Inital错误 - >的ServiceMetadataBehavior的HttpGetEnabled属性设置为true,并且HttpGetUrl属性是相对地址,但没有HTTP基址。 任一电源的HTTP基地址或设置HttpGetUrl为绝对地址。 分辨率- > http://social.msdn.microsoft.com/Forums/pl/wcf/thread/2fd858cb-8988-444f-868c-2ceea9cc9705 ,指定HttpGetUrl
AddressFilter失配误差 - >与To的“http://本地主机:8084 /的StockService / MSFT /价格”的消息不能被在接收器进行处理,由于在一个EndpointDispatcher AddressFilter失配。 检查发送者和接收者的同意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;
}
}