在ASP.NET webforms应用程序中使用WCF服务

在ASP.NET webforms应用程序中使用WCF服务,asp.net,vb.net,wcf,webforms,Asp.net,Vb.net,Wcf,Webforms,我正在尝试编写一个webforms应用程序,它可以使用wcf服务。WCF服务由windows应用程序以及我创建的windows服务使用。两者都可以很好地使用WCF服务,我的网站在部署时却不能。我遵循了有关如何在asp.net中正确使用web服务的指南。我已经创建了客户端并在代码隐藏中调用了函数。我的装订似乎是正确的 我已经研究过了,它向我展示了如何启用Tls,我已经研究过了,但它仍然不起作用 ServicePointManager.SecurityProtocol = SecurityProto

我正在尝试编写一个webforms应用程序,它可以使用wcf服务。WCF服务由windows应用程序以及我创建的windows服务使用。两者都可以很好地使用WCF服务,我的网站在部署时却不能。我遵循了有关如何在asp.net中正确使用web服务的指南。我已经创建了客户端并在代码隐藏中调用了函数。我的装订似乎是正确的

我已经研究过了,它向我展示了如何启用Tls,我已经研究过了,但它仍然不起作用

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
在调用web服务函数之前,我已经在global.asax.vb文件中添加了上述代码

我错过了什么?这是我的错误消息:

[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>

从我的web应用添加配置文件

<?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=\&quot;Web\&quot; /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配置和可以正确调用服务的客户端配置。

如果有什么我可以帮忙的,请随时告诉我。

原来问题是修改了主机文件,而我将错误的ip映射到了域名

谢谢您的帮助,稍后将在主要问题中添加这两个的配置文件。调用服务基本上是添加对WCF服务的引用,然后在代码中生成serviceclient对象,并通过客户端调用web服务方法。在winforms和服务应用程序中也采用相同的方法。从WinForm客户端配置来看,服务可以通过HTTPS正常工作。因此,调用得到了很好的执行。请再次尝试添加服务引用,检查客户端配置是否与其他配置一致。最后,调用服务。此外,我成功地调用了错误详细信息中提到的URL。它确实在https协议上运行良好,并且是由Basichttpsbinding创建的。问题似乎更多地与网站有关,而不是与WCF服务有关。您的站点和WCF项目的绑定信息是什么?我们必须设置到WCF服务的https绑定并信任WCF证书,即在localCA中安装证书。如何部署web应用程序,以及此客户端项目的站点绑定信息是什么?尝试将Http绑定配置到WCF服务,然后我们可以通过Http调用该服务。