我具有要包含在项目中的Web服务的这种配置。
环境:.Net Framework 4.5
<binding name="wsHttpBinding_ITokenService"
closeTimeout="00:01:00"
openTimeout="00:01:00"
receiveTimeout="00:01:00"
sendTimeout="00:01:00"
bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288"
maxReceivedMessageSize="65536"
messageEncoding="Text"
textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32"
maxStringContentLength="8192"
maxArrayLength="16384"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="Message">
<message clientCredentialType="Certificate"
negotiateServiceCredential="false"
establishSecurityContext="false" />
</security>
</binding>
由于我是在.net内核下进行开发的,因此我尝试将此配置转换为C#代码,但是很遗憾,我无法与Web服务进行通信。 有没有人可以帮助我进行此配置?
环境:.Net Core 2.1
services.AddTransient<Transverse.TokenService.ITokenService>(provider =>
{
var binding = new BasicHttpBinding();
binding.TextEncoding = System.Text.Encoding.UTF8;
binding.MaxReceivedMessageSize = 65536;
binding.UseDefaultWebProxy = true;
binding.BypassProxyOnLocal = false;
binding.CloseTimeout = new TimeSpan(00, 01, 00);
binding.SendTimeout = new TimeSpan(00, 01, 00);
binding.OpenTimeout = new TimeSpan(00, 01, 00);
binding.ReceiveTimeout = new TimeSpan(00, 01, 00);
binding.Security.Mode = BasicHttpSecurityMode.Message;
var httpTransport = new HttpTransportSecurity();
httpTransport.ClientCredentialType = HttpClientCredentialType.Certificate
httpTransport.ProxyCredentialType = HttpProxyCredentialType.None;
binding.Security.Transport = httpTransport;
var endpoint = new System.ServiceModel.EndpointAddress(Configuration["Services:TokenService"]);
var client = new Transverse.TokenService.TokenServiceClient(binding, endpoint);
//client.Endpoint.Address = new System.ServiceModel.EndpointAddress(Configuration["Services:TokenService"]);
return client;
});