我正在通过 HTTP 成功使用以下代码,但我想使用 SSL。当我将端点地址更改为 https 并在 web.config 中将安全模式修改为传输时,我收到错误消息:“提供的 URI 方案 'https' 无效;预期为 'http'。”
这是一个 VB.net 测试表格。
Imports WindowsApplication1.WCFService
Imports System.ServiceModel
Public Class Form1
Private WCFConnection As Service1Client 'Class reference from the ServiceReference
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If WCFConnection Is Nothing Then
WCFConnection = New Service1Client(New System.ServiceModel.BasicHttpBinding(), New EndpointAddress("https://www.mysite.com/Service1.svc?wsdl"))
End If
Dim NParray As String = WCFConnection.GetNP("8")
TextBox1.Text = NParray
End Sub
End Class
然后这里是 web.config
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" 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://www.mysite.com/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="WCFService.IService1"
name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>