没有安全性的基本HttpBinding
本文关键字:HttpBinding 安全性 | 更新日期: 2023-09-27 18:36:41
我是WCF的新手,我已经能够使用bacishttpbinding
成功地使用服务,我需要能够使用嗅探器查看服务和客户端之间的数据交换。为此,我假设我在绑定中不需要安全性,每次我尝试在绑定上没有安全性时,我都会得到以下内容:The provided URI scheme 'https' is invalid; expected '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 绑定以"关闭"安全性,则需要相应地更新基址。
例如,更改以下内容:
<add baseAddress="https://172.30.20.133:1125/HIBridge/HIBridgeService.svc"/>
自
<add baseAddress="http://172.30.20.133:1125/HIBridge/HIBridgeService.svc"/>