首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WCF路由器-非路由

WCF路由器-非路由
EN

Stack Overflow用户
提问于 2020-06-26 23:35:00
回答 1查看 103关注 0票数 0

我在控制台应用程序中有一个运行良好的WCF路由器,但我需要将其托管在Azure中。因此,我被要求将其作为web应用程序,这样它就可以作为应用程序服务托管。

我的路由器现在将其用作配置

代码语言:javascript
复制
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
  multipleSiteBindingsEnabled="true" />
<services>
  <service name="System.ServiceModel.Routing.RoutingService">
    <endpoint
              binding="basicHttpBinding"
              contract="System.ServiceModel.Routing.IRequestReplyRouter"
              name="proposalRouter" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:54636/routingService"/>

      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <serviceDebug includeExceptionDetailInFaults="true" />
      <routing filterTableName="proposalRoutingTableVersion"/>
      <serviceMetadata httpGetEnabled="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<bindings>
  <basicHttpBinding>
    <binding
      name="TestBinding"
      allowCookies="True"
      closeTimeout="00:04:00"
      openTimeout="00:00:10"
      receiveTimeout="00:05:00"
      sendTimeout="00:05:00"
      maxReceivedMessageSize="15728640">
      <security mode="None" />
    </binding>
  </basicHttpBinding>
</bindings>
<routing>
  <namespaceTable>
    <add prefix="xxx" namespace="xxxxx"/>
  </namespaceTable>
  <filters>
    <filter name="version_0_9"
            filterType="Custom"
            filterData="0.9"
            customType="RouterService.Asp.VersionFilter, RouterService.Asp"
    />
    <filter name="version_1_0"
            filterType="Custom"
            filterData="1.0"
            customType="RouterService.Asp.VersionFilter, RouterService.Asp"
    />
  </filters>
  <filterTables>
    <filterTable name="proposalRoutingTableVersion">
      <!--<add filterName="version_0_9" endpointName="version_0_9"/>
      <add filterName="version_1_0" endpointName="version_1_0"/>
      -->
      <!-- Acts as the else clause-->
      <!--
      <add filterName="noVersion" endpointName="version_0_9"/>-->

      <add filterName="version_0_9" endpointName="version_0_9" priority="1"/>
      <add filterName="version_1_0" endpointName="version_1_0" priority="0"/>

    </filterTable>
  </filterTables>
</routing>

<client>
  <endpoint address="http://localhost:63690/ProposalService_1_00.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_1_0"/>

  <!--<endpoint address="http://localhost:63690/ProposalService.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_0_9"/>-->

  <!--<endpoint address="http://localhost:63253/ProposalService.svc"
            binding="basicHttpBinding"
            contract="*"
            name="version_0_9"/>-->
</client>

这将放入版本过滤器中

代码语言:javascript
复制
public class VersionFilter : MessageFilter
{
    private string _filterData;
    private readonly XNamespace _xmlnsa = "xxxxxx";

    public VersionFilter(string filterData)
    {
        _filterData = filterData;
    }

    public override bool Match(MessageBuffer buffer)
    {
        throw new NotImplementedException();
    }

    public override bool Match(Message message)
    {
        XDocument doc = XDocument.Parse(message.ToString());

        var version = (from xml in doc.Descendants(_xmlnsa + "getProposal")
                       select xml.Attribute("version")).FirstOrDefault();

        return _filterData == version.Value.ToString(); ;
    }
}

然后给出正确或错误的响应,然后不会命中我正在尝试命中的任何一个WebService端点。

我已经在不同的地方寻找了这个问题的答案,但我看过的每个地方都显示了与我现有的代码相同\相似的代码。

一些建议谈到用EnumMember来装饰我的枚举,所以我把这个添加到了每个枚举中。这没什么用。

我已经从basic更改为wsHttpBinding,这也没有帮助,然后我得到了一个415错误。

我不明白为什么/如何从控制台应用程序更改为Web应用程序,以及ASP.Net ASP.Net应用程序会导致此操作停止。

为了不遗漏任何我看不到的东西,这是我收到的回复。

代码语言:javascript
复制
<s:Envelope
    xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <s:Fault>
            <faultcode
                xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:InternalServiceFault
            </faultcode>
            <faultstring xml:lang="en-GB">An unexpected failure occurred. Applications should not attempt to handle this error. For diagnostic purposes, this English message is associated with the failure: 'Shouldn't allocate SessionChannels if session-less and impersonating'.</faultstring>
            <detail>
                <ExceptionDetail
                    xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel"
                    xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <HelpLink i:nil="true"/>
                    <InnerException i:nil="true"/>
                    <Message>An unexpected failure occurred. Applications should not attempt to handle this error. For diagnostic purposes, this English message is associated with the failure: 'Shouldn't allocate SessionChannels if session-less and impersonating'.</Message>
                    <StackTrace>   at System.Runtime.Fx.AssertAndThrow(String description)&#xD;
   at System.ServiceModel.Routing.RoutingChannelExtension.get_SessionChannels()&#xD;
   at System.ServiceModel.Routing.RoutingService.GetOrCreateClient[TContract](RoutingEndpointTrait endpointTrait, Boolean impersonating)&#xD;
   at System.ServiceModel.Routing.ProcessRequestAsyncResult`1.StartProcessing()&#xD;
   at System.ServiceModel.Routing.ProcessRequestAsyncResult`1..ctor(RoutingService service, Message message, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Routing.RoutingService.BeginProcessRequest[TContract](Message message, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Routing.RoutingService.System.ServiceModel.Routing.IRequestReplyRouter.BeginProcessRequest(Message message, AsyncCallback callback, Object state)&#xD;
   at AsyncInvokeBeginBeginProcessRequest(Object , Object[] , AsyncCallback , Object )&#xD;
   at System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)&#xD;
   at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)&#xD;
   at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
                    <Type>System.Runtime.Fx+InternalException</Type>
                </ExceptionDetail>
            </detail>
        </s:Fault>
    </s:Body>
</s:Envelope>

我试过启用日志,但还没写完,所以不知道还能做什么。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-29 16:11:32

因此,问题出在web.config文件中的这一行

代码语言:javascript
复制
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                           multipleSiteBindingsEnabled="true" />

按照这里的建议删除这一行https://seroter.com/2010/09/19/lesson-learned-wcf-routing-service-and-the-basichttpbinding/是问题的解决方案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62598102

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档