gpt4 book ai didi

c# - WCF:提供的 URI 方案 'https' 无效;预计 'http' 。参数名称:通过当我调用 IInternal proxy = factory.CreateChannel();在客户端

转载 作者:太空狗 更新时间:2023-10-29 21:32:50 27 4
gpt4 key购买 nike

服务器的 App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehaviour">
<serviceMetadata httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</wsHttpBinding>
</bindings>

<services>
<service name="Server.InternalClass" behaviorConfiguration="NewBehaviour">
<endpoint address="IInternal" binding="wsHttpBinding" bindingConfiguration="Binding" contract="Common.IInternal">
<identity>
<dns value="MyMachine"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="https://MyMachine:8733/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>


</configuration>

客户端

static ChannelFactory<IInternal> factory = new ChannelFactory<IInternal>(new WSHttpBinding(), new EndpointAddress("https://MyMachine:8733/IInternal"));

当我调用方法 factory.CreateChannel() 时,出现错误

我配置证书

enter image description here

最佳答案

您必须告诉客户端使用安全传输 channel ,以便它使用 https 而不是 http。这是真的,因为客户端的绑定(bind)设置必须与服务端的绑定(bind)设置相匹配。

您可以通过客户端的 app.config 文件中的配置来完成此操作,或者您可以通过如下代码来完成此操作:

var ws_http_binding = new WSHttpBinding();

ws_http_binding.Security.Mode = SecurityMode.Transport;

ChannelFactory<IInternal> factory =
new ChannelFactory<IInternal>(
ws_http_binding,
new EndpointAddress("https://MyMachine:8733/IInternal"));

var channel = factory.CreateChannel();

关于c# - WCF:提供的 URI 方案 'https' 无效;预计 'http' 。参数名称:通过当我调用 IInternal proxy = factory.CreateChannel();在客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35115520/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com