WCF 路由器 - 不路由
WCF Router - Not Routing
我在控制台应用程序中有一个运行良好的 WCF 路由器,但我需要在 Azure 中托管它。因此,我被要求将其制作为 Web 应用程序,以便它可以作为应用程序服务托管。
我的路由器现在使用这个作为配置
<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>
这会落入版本过滤器
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(); ;
}
}
然后给出 true 或 false 响应,然后没有命中我试图命中的任何一个 WebService 端点。
我在很多地方寻找过这个问题的答案,但我看到的所有地方都显示了与我现有的代码相同\相似的代码。
一些建议谈到用 [EnumMember] 装饰我的枚举,所以去把它添加到每个枚举中。这没有帮助。
我已经从 basic 更改为 wsHttpBinding,这也没有帮助,然后我得到了 415 错误。
我不明白为什么\如何从控制台应用程序更改为 ASP.Net WCF 应用程序和 ASP.Net Web 应用程序会导致它停止工作。
为了不遗漏任何我没有看到的内容,这是收到的回复。
<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)
at System.ServiceModel.Routing.RoutingChannelExtension.get_SessionChannels()
at System.ServiceModel.Routing.RoutingService.GetOrCreateClient[TContract](RoutingEndpointTrait endpointTrait, Boolean impersonating)
at System.ServiceModel.Routing.ProcessRequestAsyncResult`1.StartProcessing()
at System.ServiceModel.Routing.ProcessRequestAsyncResult`1..ctor(RoutingService service, Message message, AsyncCallback callback, Object state)
at System.ServiceModel.Routing.RoutingService.BeginProcessRequest[TContract](Message message, AsyncCallback callback, Object state)
at System.ServiceModel.Routing.RoutingService.System.ServiceModel.Routing.IRequestReplyRouter.BeginProcessRequest(Message message, AsyncCallback callback, Object state)
at AsyncInvokeBeginBeginProcessRequest(Object , Object[] , AsyncCallback , Object )
at System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
<Type>System.Runtime.Fx+InternalException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
我试过启用日志,但还没写到日志,所以不确定还能尝试或做什么。
所以,事实证明 web.config 文件中的这一行是问题所在
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
按照此处的建议删除此行 https://seroter.com/2010/09/19/lesson-learned-wcf-routing-service-and-the-basichttpbinding/ 是问题的解决方案。
我在控制台应用程序中有一个运行良好的 WCF 路由器,但我需要在 Azure 中托管它。因此,我被要求将其制作为 Web 应用程序,以便它可以作为应用程序服务托管。
我的路由器现在使用这个作为配置
<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>
这会落入版本过滤器
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(); ;
}
}
然后给出 true 或 false 响应,然后没有命中我试图命中的任何一个 WebService 端点。
我在很多地方寻找过这个问题的答案,但我看到的所有地方都显示了与我现有的代码相同\相似的代码。
一些建议谈到用 [EnumMember] 装饰我的枚举,所以去把它添加到每个枚举中。这没有帮助。
我已经从 basic 更改为 wsHttpBinding,这也没有帮助,然后我得到了 415 错误。
我不明白为什么\如何从控制台应用程序更改为 ASP.Net WCF 应用程序和 ASP.Net Web 应用程序会导致它停止工作。
为了不遗漏任何我没有看到的内容,这是收到的回复。
<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)
at System.ServiceModel.Routing.RoutingChannelExtension.get_SessionChannels()
at System.ServiceModel.Routing.RoutingService.GetOrCreateClient[TContract](RoutingEndpointTrait endpointTrait, Boolean impersonating)
at System.ServiceModel.Routing.ProcessRequestAsyncResult`1.StartProcessing()
at System.ServiceModel.Routing.ProcessRequestAsyncResult`1..ctor(RoutingService service, Message message, AsyncCallback callback, Object state)
at System.ServiceModel.Routing.RoutingService.BeginProcessRequest[TContract](Message message, AsyncCallback callback, Object state)
at System.ServiceModel.Routing.RoutingService.System.ServiceModel.Routing.IRequestReplyRouter.BeginProcessRequest(Message message, AsyncCallback callback, Object state)
at AsyncInvokeBeginBeginProcessRequest(Object , Object[] , AsyncCallback , Object )
at System.ServiceModel.Dispatcher.AsyncMethodInvoker.InvokeBegin(Object instance, Object[] inputs, AsyncCallback callback, Object state)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</StackTrace>
<Type>System.Runtime.Fx+InternalException</Type>
</ExceptionDetail>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
我试过启用日志,但还没写到日志,所以不确定还能尝试或做什么。
所以,事实证明 web.config 文件中的这一行是问题所在
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
按照此处的建议删除此行 https://seroter.com/2010/09/19/lesson-learned-wcf-routing-service-and-the-basichttpbinding/ 是问题的解决方案。