Windows服务中的WCF托管问题

时间:2012-05-09 05:39:35

标签: .net wcf rest

我已经创建了一个REST WCF服务。

首先我在Console应用程序中托管,它工作正常。

然后我在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>

我试过排查但没有成功。

以下是目前采取的步骤

  1. 初始错误 - &gt; ServiceMetadataBehavior的HttpGetEnabled属性设置为true,HttpGetUrl属性是相对地址,但没有http基址。提供http基址或将HttpGetUrl设置为绝对地址。 分辨率 - &gt; http://social.msdn.microsoft.com/Forums/pl/wcf/thread/2fd858cb-8988-444f-868c-2ceea9cc9705,指定的HttpGetUrl

  2. AddressFilter不匹配错误 - &gt;由于EndpointDispatcher上的AddressFilter不匹配,无法在接收方处理带有'http:// localhost:8084 / StockService / MSFT / Price'的消息。检查发送方和接收方的EndpointAddresses是否一致。 分辨率 - &gt;添加了行为 - &gt; [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any)]

  3. 现在ContractFilter不匹配异常 - &gt; System.ServiceModel.FaultException:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理带有Action''的消息。

  4. 似乎我错过了一些基础知识,但到目前为止还没有任何线索。

    合同

     [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;
            }
       }
    

0 个答案:

没有答案