[英]Consume WCF service within ASP.NET webforms application
我正在尝试编写一个可以使用 wcf 服务的网络表单应用程序。 WCF 服务由 windows 应用程序以及我创建的 windows 服务使用。 两者都可以正常使用 WCF 服务,但是我的网站在部署时不能。 我遵循了有关如何在 asp.net 中正确使用 web 服务的指南。 我已经创建了客户端并在后面的代码中调用了 function。 我的绑定似乎是正确的。
我已经研究过,它显示我启用了 Tls,我已经启用了,但它仍然无法正常工作。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Or
SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
我已经在我的 global.asax.vb 文件中以及在调用我的 web 服务 function 之前添加了上述代码。
我在这里想念什么? 这是我的错误信息:
[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=\"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配置和可以正常调用服务的客户端配置。
如果有什么我可以帮忙的,请随时告诉我。
原来问题是修改主机文件,我有错误的 ip 映射到域名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.