Dot-Net
使用 https 端點添加 WCF 服務引用
我的 WCF 服務應用程序通過 http 和 https 工作,但是,當我在客戶端中向它添加服務引用(使用 https url)時,Visual Studio 2010 將配置文件中的端點設置為 http。這似乎不像將配置端點更改為 https 那樣簡單,因為幕後有多個文件在使用 xsd 並引用 http 端點。如何設置我的服務/客戶端以強制使用 https 以便正確設置端點?
當我嘗試手動更改配置文件中的端點並將安全模式設置為“傳輸”時,我收到此錯誤:
異常消息:在 <https://myservice/AvailabilityService.svc>上沒有可以接受消息的端點偵聽。這通常是由不正確的地址或 SOAP 操作引起的。有關更多詳細資訊,請參閱 InnerException(如果存在)。
但是,我可以在 IE 中看到該端點,並且正在本地調試。在我使用 https 添加我的服務引用並蒐索其 http 等效項的解決方案後,它會找到一個引用 http 的 wsdl 文件、一個 configuration.svcinfo 和一個使用 http url 而不是 https 的 configuration91.svcinfo
這是我的伺服器端配置:
<?xml version="1.0"?> <configuration> <system.web> <compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel> <behaviors> <serviceBehaviors> <behavior> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true"/> </behavior> </serviceBehaviors> </behaviors> <serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer> <modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>..和客戶端配置:
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IAvailabilityService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"> <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" /> <security mode="Transport"> <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> <message clientCredentialType="UserName" algorithmSuite="Default" /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address="https://myservice/AvailabilityService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAvailabilityService" contract="PaymentAvailabilityService.IAvailabilityService" name="BasicHttpBinding_IAvailabilityService" /> </client> </system.serviceModel>也許我最好手動使用程式碼中的服務?
您需要更改綁定以使用傳輸安全性來使用 HTTPS
您的伺服器端綁定應配置為 https 以及客戶端:
<bindings> <basicHttpBinding> <binding name="httpsBinding" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> <security mode="Transport"> <transport clientCredentialType="None" /> </security> </binding> </basicHttpBinding> </bindings> <services> <service name="yourNamespace.YourService" behaviorConfiguration="yourBehaviors"> <endpoint contract="yourNamespace.YourService" binding="basicHttpBinding" bindingConfiguration="httpsBinding" /> </service> </services>