Iis
使用 IIS ARR 和 URL Rewrite 將 Webservice 請求發送到新伺服器
我們正在嘗試將我們的 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>
這是實現這一目標的正確方法嗎?還是我需要考慮以另一種方式解決問題?
提前致謝。
通過使用 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>