- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我为我现在的雇主开发了一个客户端/服务器应用程序,其中一个要求是客户端部分作为 DLL 分发。由于 DLL 不“执行”dllName.dll.config 文件,因此我需要将配置移动到代码中。我已尽我所能做到这一点,但我现在遇到了这个异常(exception);
The X.509 certificate CN=ComputerName chain building failed.
The certificate that was used has a trust chain that cannot be verified. Replace the certificate or change the certificateValidationMode. An internal certificate chaining error has occurred.
我已经用 google 搜索过,并以其他方式搜索过这个问题的解决方案,但到目前为止,我找不到任何对我所见过的各种接近但不是真的解决方案有足够清晰解释的内容。
无论如何,My LocalStore 中有一个证书,但它实际上仅供服务器使用(目前正在同一个 XP Pro 机器上测试客户端和服务器),至少,据我所知是这样。 (对 WCF 还是很陌生)(请注意下面的客户端配置文件如何不获取或以其他方式向客户端指出上述证书。
客户端的 app.config 如下所示,通过我们的测试 EXE 运行良好,其中包含此配置文件的部分。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="MyTcpBinding_IFileXferService"
receiveTimeout="02:00:00"
sendTimeout="02:00:00"
transferMode="Streamed"
maxBufferSize="65536"
maxReceivedMessageSize="2147483647">
<readerQuotas maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="65536" />
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="ClientConfigBehavior">
<dataContractSerializer maxItemsInObjectGraph="6553600" />
<clientCredentials>
<serviceCertificate>
<authentication certificateValidationMode="None" />
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint name="ClientConfig"
binding="netTcpBinding"
bindingConfiguration="MyTcpBinding_IFileXferService"
behaviorConfiguration="ClientConfigBehavior"
contract="ServiceRefs.IFileXferService" />
</client>
</system.serviceModel>
</configuration>
但现在我已经将配置信息移到代码中(这样 DLL 可以在没有 .config 文件的情况下分发),我再次遇到上述异常。 (顺便说一句,如果我们发现给定的设置需要更改,我可以将其添加到我们自己的 xml 配置文件中。)
用于替换上述配置的代码如下所示:
...
netTcpBinding = new NetTcpBinding();
endpointAddr = new EndpointAddress(HostURI);
updateMaxItemsBehavior(); // method below this snippet
TimeSpan tsTwoHours = new TimeSpan(2,0,0);
netTcpBinding.ReceiveTimeout = tsTwoHours;
netTcpBinding.SendTimeout = tsTwoHours;
netTcpBinding.TransferMode = TransferMode.Streamed;
netTcpBinding.MaxBufferSize = 65536;
netTcpBinding.MaxReceivedMessageSize = 2147483647;
netTcpBinding.ReaderQuotas.MaxStringContentLength = 2147483647;
netTcpBinding.ReaderQuotas.MaxArrayLength = 2147483647;
netTcpBinding.ReaderQuotas.MaxBytesPerRead = 65536;
// double the 64k default
netTcpBinding.MaxBufferPoolSize = 131072;
netTcpBinding.Security.Mode = SecurityMode.Transport;
netTcpBinding.Security.Transport.ClientCredentialType =
TcpClientCredentialType.None;
// now to instantiate the service proxy client
svcClient = new FileXferServiceClient(netTcpBinding, endpointAddr);
我已经用这些接下来的位的各种组合尝试过这个,但不能绕过该死的异常。
// Set the certificate for the client.
X509Certificate2 cert = new X509Certificate2();
svcClient.ClientCredentials.ClientCertificate.Certificate = cert;
//svcClient.ClientCredentials.ClientCertificate.SetCertificate(
// StoreLocation.LocalMachine,
// StoreName.My,
// X509FindType.FindByThumbprint,
// "ThumbprintThumbprintThumbprintThumbprint");
// here's this
//
private void updateMaxItemsBehavior()
{
svcEndpoint = new ServiceEndpoint(
new ContractDescription("IFileXferService"));
foreach (OperationDescription operation in
svcEndpoint.Contract.Operations)
{
operation.Behaviors
.Find<DataContractSerializerOperationBehavior>()
.MaxItemsInObjectGraph = 6553600;
}
}
总而言之,我们的测试 Winforms 应用程序(以及我们的 WCF 应用程序的客户端)在 wfappname.exe.config 文件中的配置设置下运行良好,但现在我已尝试将其全部移动到代码中,它显然需要证书。我想我真正希望的是“我如何在代码中复制上面的 app.config,以便我的 WCF 客户端不需要 app.config。”
谁能帮我解决这个问题? (我会成为你最好的 friend !); )
谢谢,斯科特
最佳答案
我觉得你是个男人。
我不喜欢这样的想法,例如,当 WCF 服务部署到 IIS 中时,我必须将 .config 内容嵌入到 web.config 中,或者在以其他方式托管时转换 .config 并嵌入到代码中.
我解决这个问题的方法是使用覆盖默认 ApplyConfiguration() 的自定义服务主机逻辑。在服务端,它允许 WCF DLL 在 dllname.dll.config(或任何地方)中查找其配置。
是all explained here .该信息也在 this answer on Stackoverflow 中重复。 .
您使用的是 WCF 客户端,因此您需要覆盖 ApplyConfiguration() method in a custom ChannelFactory .这是描述here .在同一篇论坛帖子中,描述了一种替代技术,您可以在其中覆盖 CreateDescription()并指定另一个 .config 文件路径。这些方法非常相似;两者都应该在 WCF 客户端中工作。
您还可以考虑将 .config 作为资源嵌入到 .dll 中。这样,您仍然有一个单文件分发(dll),但您可以使用 xml 配置语法来指定所有内容。在构建时,将 .config 文件嵌入到 DLL 中。在您的自定义 ApplyConfiguration() 运行时,您必须调用 Assembly.GetManifestResourceStream(); ,传递字符串“dllname.dll.config”以获取包含配置信息的只读流。
如果您希望允许用户覆盖嵌入式配置,那么您可以将该智能引入您自己的 ApplyConfiguration() 实现中。可能先寻找文件系统文件;如果它不存在,则回退到嵌入式 .config 文件。
这个答案并没有真正告诉您如何将配置设置移动到代码中,因为我认为这是一个令人发指的想法。但也许它无论如何都能解决您的问题。
关于c# - 需要如何帮助将 system.serviceModel 配置部分移动到我的代码中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4110178/
我正在 IIS 中运行我的 Web 项目。 这是一个4.0框架的APP。 我有一个 Service.svc,当我运行我的应用程序时收到此错误。 "Could not load type 'System
有一段时间,我在尝试使用 Azure 模拟器启动任何类型的应用程序时遇到以下错误: Microsoft Azure Tools: Method not found: 'Void Microsoft.W
我有一个由针对 .NET Standard 2.0 和 .NET Core 2.1.304 的项目组成的解决方案。在构建此解决方案时,它利用了旧的易受攻击版本的 System.ServiceModel
现象: 最近遇到了WCF 服务无法调用的错误,异常如下。 System.ServiceModel.ProtocolException, System.ServiceModel, Version=4
我在可移植类库中有一个接口(interface),启用了构建时的代码分析。当我用 WCF 服务的 ServceContract 和 OperationContract 标记它时,它开始从代码分析中抛出
我正在 sharepoint 上部署 webpart 并遇到一些错误。 webpart 使用来自 Web 服务的数据并使用 Microsoft Chart (Framework 3.5) 显示图表。当
我正在学习 WCF 并找到了 this article在一个简单的 WCF 示例中。 在下面的代码中(来自上面的文章),为什么System.ServiceModel.Dispatcher.Channe
我们有一个启动WCF服务器的应用程序,该应用程序从中读取数据。 它会启动,并且可以在所有Windows XP计算机上正常阅读。 但是,在Vista机器上,我们得到: System.ServiceMod
如果此问题在 stackOverflow 上出现两次,我们深表歉意 我试图在 Windows Server 2003 机器上运行 wcf 服务。我收到了 System.ServiceModel.Add
您好,当应用程序托管在服务器中时,我遇到了以下错误。该应用程序在本地盒子上运行良好。“已超过传入消息的最大消息大小配额 (100000000)。要增加配额,请在适当的绑定(bind)元素上使用 Max
我在 Win7(64 位)上使用 VS2010 express,我正在尝试使用 System.ServiceModel 但我收到一个错误,指出没有 ServiceModel System 命名空间:
我想在我的 Unity 应用程序中使用 WCF 服务(通过命名管道)。因此,我包括以下两个命名空间: using System.ServiceModel; using System.ServiceMo
我有以下代码: public partial class MyServiceClient : System.ServiceModel.ClientBase 派生,请使用此选项 m_MyClient.S
如何在我的应用程序中调试 system.servicemodel 类? 最佳答案 听起来您对调试 .NET 框架代码本身感兴趣吗?如果是这样,微软已经向公众发布了大部分 .NET 框架的源代码。 但是
我发现的所有与智能感知相关的问题似乎都与自定义配置设置有关。我正在尝试在已从 web.config 移出到 service.config 的 .net 标准部分上获得智能感知。 有办法吗? 最佳答案
我在客户端应用程序上遇到了这个异常,不知道如何解决这个问题。 当返回的数据(价格列表)超过 15MB,但适用于小于 15MB 的消息时,我遇到了这个异常。 错误消息: 接收对“http://local
我创建了一个 Core 3.1 应用程序,该应用程序使用基于 .net 标准 2.0 的 Web 服务。 在本地开发环境中,一切正常。在我将其部署到 UAT (IIS) 上之前,我收到以下异常: Ex
我添加了一个名为 http://192.168.5.180:8080/intg/CrmWebService.asmx 的服务引用。名称为 CrmWebProxy。 下面是代码行。 Microsoft.
当我将网站发布到我的 plesk 服务器时,我收到以下错误: Unrecognized configuration section system.serviceModel. 最佳答案 您的主机支持哪个
有什么方法可以访问“System.ServiceModel”客户端配置,即基于类 (dll) 项目中的 app.config? 最佳答案 ConfigurationManager.GetSection
我是一名优秀的程序员,十分优秀!