2011-03-16 96 views
1

我试图建立一个WCF服务供内部使用,我们面向外部的网络农场(我们没有内部Web场,我需要这个服务有故障转移和负载平衡)。如何? WCF customBinding通过HTTPS

要求:

  • 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,如果需要可以确认。

回答

0

好的,你的问题是你还没有定义地址为你服务。记住端点的ABC:地址绑定 - 合同。

您需要为您的.svc文件管理的服务定义一个地址,以及可以从您的IIS浏览文件的位置。无论该.svc文件的URL是什么,您都会添加您定义的地址(在您的情况下为空字符串),然后将其添加到顶端。所以如果我把我的服务。在根SVC文件,它成为

https://localhost/myservice.svc/<ServiceAddress>

在你的情况ServiceAddress=""所以URL是https://localhost/myservice.svc/

更多信息,请参见here

+0

有在web.config中的地址,所以我只能假设你指的是地址从客户端的app.config丢失?为什么缺少?我所做的只是输入相同的URL(我可以浏览并查看WSDL页面),进入“添加服务引用”选项,并找到该服务。然后我输入一个名称空间,点击GO,就是这样。这就是我过去做WCF的过程。任何想法为什么它没有把地址放在app.config中? – AaronC 2011-03-17 01:07:25

+0

好的,其明显的问题是,在客户端侧的app.config不具有标签下的任何信息。我知道需要知道a)为什么在执行“添加服务参考”时没有自动填充; b)如何让它自动填充? c)或者,更改web.config绑定或其他东西,以便自动填充,就像之前一样。它必须*使用我们服务的开发人员不必编辑他们的app.configs来使用此服务。他们应该能够在“添加服务参考”中输入URL,然后开始使用该服务。谢谢你的帮助! – AaronC 2011-03-17 01:19:39

+0

注意:我读过我必须从这篇文章创建一个customBinding:http://stackoverflow.com/questions/4396961/why-wcf-instancecontextmode-persession-is-not-working-over-https。我也看到了,我是有终点的详细内容不填充到客户端的app.config遇到的问题是,因为与结合(但没有提供解决方案)的问题。我可以使用wsHttpBinding代替(或其他?),并且通过https仍然具有PerSession上下文吗? – AaronC 2011-03-17 02:37:07