2

我创建了一个 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>

我试图排除故障,但没有成功。

以下是迄今为止采取的步骤

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

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

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

好像我缺少一些基础知识,但到目前为止还没有任何线索。

合同

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

0 回答 0