我们正在尝试将我们的 Web 服务从 Azure 云服务移动到 Azure Web 应用,这将改变它们的地址,但我们有一些客户端无法更新它们正在使用的地址,因此我们正在寻找一种方法来使用当前的云服务服务器作为这些客户端的消息转发服务器。
我不是 IIS 管理员,因此我尝试进行一些搜索并找出如何使用 ARR 和 URL Rewrite 来执行此操作,但它似乎不起作用,所以我在想这是否是正确的方法!
我已在 ARR 中启用代理,并在 IIS 中为我的应用程序创建了重写规则。以下是旧地址的 web.config 中的结果重写规则:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<outboundRules>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://new-address.azurewebsites.net/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这是实现此目标的正确方法吗?还是我需要研究其他方法来解决此问题?
提前致谢。
答案1
通过使用 RoutingService 而不是 AAR 和 Url 重写解决了该问题!只需在空文件夹中添加一个 web.config 文件即可完成!
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<serviceActivations>
<add factory="System.ServiceModel.Activation.ServiceHostFactory" relativeAddress="./MyService.svc"
service="System.ServiceModel.Routing.RoutingService,System.ServiceModel.Routing, version=4.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
</serviceActivations>
</serviceHostingEnvironment>
<services>
<service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="DefaultServiceBehavior">
<endpoint name="basicHttpSampleService" address="" binding="wsHttpBinding" bindingConfiguration="sslBinding" contract="System.ServiceModel.Routing.IRequestReplyRouter" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<routing filterTableName="routingFilterTable" routeOnHeadersOnly="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<routing>
<filters>
<filter name="AddressFilter" filterType="MatchAll"/>
</filters>
<filterTables>
<filterTable name="routingFilterTable">
<add filterName="AddressFilter" endpointName="basicHttpSampleServiceClient"/>
</filterTable>
</filterTables>
</routing>
<bindings>
<wsHttpBinding>
<binding name="sslBinding" receiveTimeout="00:05:00" sendTimeout="00:05:00" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://new-address.azurewebsites.net/MyService.svc"
binding="wsHttpBinding" bindingConfiguration="sslBinding"
contract="*" name="basicHttpSampleServiceClient" />
</client>
</system.serviceModel>
</configuration>