asp.net - 在 ASP.NET webforms 应用程序中使用 WCF 服务
问题描述
我正在尝试编写一个可以使用 wcf 服务的 webforms 应用程序。Windows 应用程序以及我创建的 Windows 服务都使用 WCF 服务。两者都可以很好地使用 WCF 服务,但是我的网站在部署时不能。我遵循了有关如何在 asp.net 中正确使用 Web 服务的指南。我已经创建了客户端并在后面的代码中调用了该函数。我的绑定似乎是正确的。
我已经研究过,它显示我启用了 Tls,我已经启用了,但它仍然无法正常工作。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
我已经在我的 global.asax.vb 文件中以及在调用我的 Web 服务函数之前添加了上述代码。
我在这里想念什么?这是我的错误信息:
[CommunicationException: An error occurred while making the HTTP request to
https://myserviceD.net/Service.svc.This could be due to the fact that the
server certificate is not configured properly with HTTP.SYS in the HTTPS case.
This could also be caused by a mismatch of the security binding between the
client and the server.]
这是我的 WCF 配置文件:
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5">
</compilation>
<httpRuntime targetFramework="4.5"/>
<pages>
<namespaces>
<add namespace="System.Runtime.Serialization"/>
<add namespace="System.ServiceModel"/>
<add namespace="System.ServiceModel.Web"/>
</namespaces>
</pages>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text"/>
</basicHttpBinding>
<basicHttpsBinding>
<binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
<readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpsBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
还有一个成功使用 Web 服务的 winforms 配置文件:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<appSettings>
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
<binding name="BasicHttpsBinding_IService1">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://myserviceD.net/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpsBinding_IService1" contract="myserviceD.ServiceReference.IService"
name="BasicHttpsBinding_IService1" />
</client>
</system.serviceModel>
</configuration>
从我的网络应用程序添加配置文件
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
</configSections>
<system.web>
<customErrors mode="Off"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpsBinding_IService">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https:///myserviceD.net/Service.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpsBinding_IService" contract="myserviceD.net.ServiceReference.IService"
name="BasicHttpsBinding_IService" />
</client>
</system.serviceModel>
</configuration>
解决方案
错误详情主要说明服务有问题,比如服务在https上不能正常工作。
您如何在客户端调用服务?在可以正确使用服务的其他应用程序中,自动生成的配置是什么?我怀疑通过 HTTPS 提供的服务有问题。它可能只能通过 HTTP 工作。此外,此问题与 TLS 版本无关,由操作系统决定 TLS 版本。
我想知道服务器端的WCF配置和可以正确调用服务的客户端配置。
如果有什么我可以帮忙的,请随时告诉我。
推荐阅读
- sequelize.js - 如何在 LEFT JOIN 中嵌套 INNER JOIN
- ruby-on-rails - 在 Rails 中更新类似计数而不重新加载页面
- php - 查了查询,数据库,表名,列名等,还是不知道为什么会出现这个错误
- python - Cython 内存视图会很慢吗?
- r - 将多个时区转换为一个 - r
- php - 如何防止该页面在 jQuery 中“跳到顶部”?
- java - angular和java常用的加解密
- r - 有没有一种快速的方法来提取数据框列表中的元素?
- docker - Docker 创建命令挂在“等待主机启动”
- css - React js css内联样式边距不起作用