提供的 URI 方案'http'无效;预期的"https"。参数名称



我经历了一些以前的问题,但我认为在某处缺失,因为WCF对我来说是全新的。

WCF 服务应用程序中的 web.config

<service behaviorConfiguration="BehaviourName" name="ProjectName.ServiceName">
<endpoint address="" binding="basicHttpBinding" contract="ProjectName.IServiceName">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="https://aaa.bbbbbb.com/IISDeployedFolderName"/>
</baseAddresses>
</host>
</service>
....................
.....................
<behavior name="BehaviourName">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
............................
..........................
<basicHttpBinding>
<binding name="secureHttpBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="Certificate" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
..........................
.........................
<protocolMapping>
<add binding="basicHttpBinding" scheme="https" />
</protocolMapping>
............................
..............................

在 MVC 应用程序中,其他应用程序正在使用上述代码服务。

添加了默认设置的服务引用,并使用HTTP自动生成端点地址,如果我将其更改为HTTPS,则会因错误而中断。

在 WCF 中,我们应该为HTTPS协议配置一个额外的服务终结点,这需要传输层安全模式。

<services>
<service name="WcfService1.Service1">
<!--please pay attention to that apply the binding configuration by means of bindingConfiguration property.-->
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="mybinding">
<security mode ="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>

以下配置同时支持 HTTP 协议和 HTTPS 协议。

<system.serviceModel>
<services>
<service name="WcfService1.Service1">
<!--please pay attention to that apply the binding configuration by means of bindingConfiguration property.-->
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1" bindingConfiguration="mybinding"></endpoint>
<endpoint address="" binding="basicHttpBinding" contract="WcfService1.IService1"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="mybinding">
<security mode ="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>

我们还可以使用ProtocolMapping部分来简化配置。以下配置同时支持 HTTP 和 HTTPS 协议。

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<protocolMapping>
<add binding="basicHttpBinding" scheme="http"/>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
</system.serviceModel>

公文。

https://learn.microsoft.com/en-us/dotnet/framework/wcf/simplified-configuration 如果有什么我可以帮忙的,请随时告诉我。

相关内容

  • 没有找到相关文章

最新更新