gpt4 book ai didi

c# - 没有安全性的 BasicHttpBinding

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:46 26 4
gpt4 key购买 nike

我是 WCF 的新手,我已经能够使用 bacishttpbinding 成功地使用服务,我需要能够使用嗅探器查看服务和客户端之间的数据交换。为此,我假设我不需要在绑定(bind)中有任何安全性,每次我尝试在我的绑定(bind)中没有安全性时,我都会得到以下信息:The provided URI scheme 'https' is invalid;应为“http”。

如何将服务和客户端配置为没有安全性,以便我可以嗅探纯 XML 中的数据传输?

服务配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<customErrors mode="Off"/>
</system.web>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="All" propagateActivity="true">
<listeners>
<add name="xml"/>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="All">
<listeners>
<add name="xml"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="D:\Technology\Production\wwwRoot\medical\log\Log.svclog"/>
</sharedListeners>
<!--
<sources>
<source name="System.ServiceModel"
switchValue="All"
propagateActivity="true">
<listeners>
<add name="traceListener"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData="D:\Technology\Production\wwwRoot\medical\log\Traces.svclog" />
</listeners>
</source>
</sources>
-->
</system.diagnostics>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="25000">
<filters>
<clear/>
</filters>
</messageLogging>
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior name="SecureBehave">
<serviceCredentials>
<clientCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</clientCertificate>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="HIBridgeLib.HIBridgeService.Security.MessageSecurityValidator, HIBridgeLib"/>
<!--
<serviceCertificate findValue="WCfServer"
storeLocation="CurrentUser"
storeName="My"
x509FindType="FindBySubjectName" />
-->
</serviceCredentials>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="HIBridge_SSLBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="Certificate" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" negotiateServiceCredential="True" establishSecurityContext="True"/>
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="HIBridge_BasicBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
</security>
<readerQuotas maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="HIBridgeWebService.HIBridgeService" behaviorConfiguration="SecureBehave">
<endpoint address="basic" binding="basicHttpBinding" bindingConfiguration="HIBridge_BasicBinding" contract="HIBridgeLib.HIBridgeService.IHIBridgeService"></endpoint>
<endpoint address="ws" binding="wsHttpBinding" bindingConfiguration="HIBridge_SSLBinding" contract="HIBridgeLib.HIBridgeService.IHIBridgeService"></endpoint>
<host>
<baseAddresses>
<add baseAddress="https://172.30.20.133:1125/HIBridge/HIBridgeService.svc"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<connectionStrings>
<clear/>
<add name="DBConnectionString" connectionString="Data Source=(local)\SQLEXPRESS;Initial Catalog=HIBridge;User ID=CF;Password=C01dFu$i0n" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.webServer>
<handlers accessPolicy="Read, Script"/>
<directoryBrowse enabled="false"/>
<defaultDocument>
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
<httpErrors>
<clear/>
</httpErrors>
</system.webServer>
</configuration>

客户端配置如下:

System.ServiceModel.BasicHttpBinding basicHTTPSBinding = new System.ServiceModel.BasicHttpBinding();
basicHTTPSBinding.Name = "HIBridge_BasicBinding";
basicHTTPSBinding.OpenTimeout = TimeSpan.FromMinutes(1);
basicHTTPSBinding.CloseTimeout = TimeSpan.FromMinutes(1);
basicHTTPSBinding.SendTimeout = TimeSpan.FromMinutes(1);
basicHTTPSBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
basicHTTPSBinding.BypassProxyOnLocal = false;

basicHTTPSBinding.HostNameComparisonMode = System.ServiceModel.HostNameComparisonMode.StrongWildcard;
basicHTTPSBinding.MaxBufferPoolSize = 2147483647;
basicHTTPSBinding.MaxReceivedMessageSize = 2147483647;
basicHTTPSBinding.MessageEncoding = System.ServiceModel.WSMessageEncoding.Text;
basicHTTPSBinding.TextEncoding = Encoding.UTF8;
basicHTTPSBinding.UseDefaultWebProxy = true;
basicHTTPSBinding.AllowCookies = false;
basicHTTPSBinding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;
basicHTTPSBinding.Security.Transport.ClientCredentialType = System.ServiceModel.HttpClientCredentialType.None;
basicHTTPSBinding.Security.Transport.ProxyCredentialType = System.ServiceModel.HttpProxyCredentialType.None;
basicHTTPSBinding.Security.Transport.Realm = "";

System.ServiceModel.EndpointAddress endpointAddress = null;

if (LocalMedCart.CartProfile.ConsoleHostname.Contains("/HIBridge/HIBridgeService.svc"))
endpointAddress = new System.ServiceModel.EndpointAddress(LocalMedCart.CartProfile.ConsoleHostname + "/basic");
else
endpointAddress = new System.ServiceModel.EndpointAddress(string.Format("https://{0}:{1}/HIBridge/HIBridgeService.svc/basic", LocalMedCart.CartProfile.ConsoleHostname, LocalMedCart.CartProfile.CommunicationPort));


HIBridgeLib.HIBridgeService.Security.PermissiveCertificatePolicy.Enact(string.Format("CN={0}", LocalMedCart.CertificateName));

serviceProxy = new HIBridgeLib.HIBridgeService.HIBridgeServiceProxy(basicHTTPSBinding, endpointAddress);
serviceProxy.ClientCredentials.UserName.UserName = "username";
serviceProxy.ClientCredentials.UserName.Password = "password";

最佳答案

如果将 WCF 绑定(bind)更新为“关闭”安全性,则需要相应地更新基地址。

例如,更改以下内容:

<add baseAddress="https://172.30.20.133:1125/HIBridge/HIBridgeService.svc"/>

<add baseAddress="http://172.30.20.133:1125/HIBridge/HIBridgeService.svc"/>

关于c# - 没有安全性的 BasicHttpBinding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27841721/

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