【发布时间】:2011-07-17 00:37:35
【问题描述】:
我正在尝试在我们面向外部的网络场上设置一个供内部使用的 WCF 服务(我们内部没有网络场,我需要此服务来进行故障转移和负载平衡)。
要求:
- PerSession 状态,因为我们需要服务为每个会话保留可变数据。
- HTTPS。经过大量谷歌搜索后,我阅读了我需要创建一个 customBinding,我已经完成了,但不确定它是否正确。
- 消息更大,因为参数之一是 byte[] 数组,最大可以为 5mb。
- 无需手动编辑客户端 app.config。即,我需要开发人员只添加服务引用,然后开始使用该对象,而无需繁琐地更改 app.config。
注意:我之前已经让这个服务在 HTTP 下正常工作(使用 wsHttpBinding)。 我也让它在 HTTPS 下工作,但它不支持 PerSession 状态,并且每次函数调用都会丢失内部变量值。
我目前从测试工具中收到此错误:
在 ServiceModel 客户端配置部分中找不到引用合同“AppMonitor.IAppMonitorWcfService”的默认端点元素。这可能是因为找不到您的应用程序的配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。
注意:错误是在测试工具 EXE 上出现的,它在服务引用下直接引用了 WCF 服务。这不是 exe 引用另一个对象的问题,然后引用了我读过的 WCF 服务。
浏览到 URL 时 WSDL 正确显示。
Web.Config:
<system.serviceModel>
<services>
<service name="AppMonitor.AppMonitorWcfService" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="customBinding" bindingConfiguration="EnablePerSessionUnderHttps" contract="AppMonitor.IAppMonitorWcfService"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<customBinding>
<binding name="EnablePerSessionUnderHttps" maxReceivedMessageSize="5242880">
<reliableSession ordered="true"/>
<textMessageEncoding>
<readerQuotas maxDepth="64" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
</textMessageEncoding>
<httpsTransport authenticationScheme="Anonymous" requireClientCertificate="false"/>
</binding>
</customBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
EXE 的 App.config(添加服务引用时自动生成):
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="CustomBinding_IAppMonitorWcfService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="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" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="true" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client />
</system.serviceModel>
</configuration>
我不确定 app.config 为什么显示 wsHttpBinding?这不应该是customBinding吗? 我真的不想编辑 app.config,因为该服务将被数十名开发人员使用,我希望他们能够添加服务参考,然后他们就走了......
使用 VS2008、.NET 3.51。 我认为服务器是IIS7,Win Server 2008,如果需要可以确认。
【问题讨论】: