2011-08-18 165 views
0

我正在开发一个WCF服务,将由客户在互联网上调用。该服务托管在IIS7中,只接受http。对于客户从https呼叫我们,我们确实有一个反向代理,将请求转发到https https应用程序。客户提供https连接,并顺利进行,并正确添加对服务的引用。问题调用WCF服务互联网

System.ArgumentException:试图创建一个客户端,并添加您的端点HTTPS和执行它时,它读取这个问题是所提供的URI方案的“https”是无效的,
预期的“http”。参数名称:via。

我离开服务的web.config的一部分:

<bindings> 
<wsHttpBinding> 
    <binding name="ConfigEP"> 
    <security mode="Message"> 
    <message clientCredentialType="Certificate" /> 
    </security> 
    </binding> 
</wsHttpBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"> 
<baseAddressPrefixFilters> 
    <add prefix="http://serverInterno/App/"/> 
</baseAddressPrefixFilters> 
</serviceHostingEnvironment> 
<services> 
<service behaviorConfiguration="App.AppM_NameBehavior" name="App.AppM_Name"> 
    <endpoint address="" behaviorConfiguration="App.AppM_NameEPBehavior" binding="wsHttpBinding" bindingConfiguration="ConfigEP" name="App.AppM_NameEP" bindingNamespace="http://siteName/AppM_Name" contract="App.IAppM_Name" /> 
</service> 
</services> 
<behaviors> 
<endpointBehaviors> 
    <behavior name="App.AppM_NameEPBehavior"> 
    <wsdlExtensions location="https://urlsegura/App/Appm_Name.svc" singleFile="true" /> 
    </behavior> 
</endpointBehaviors> 
<serviceBehaviors> 
    <behavior name="App.AppM_NameBehavior"> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
    <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" /> 
    <serviceCredentials> 
    <clientCertificate> 
    <authentication customCertificateValidatorType="App.Validador, App" certificateValidationMode="Custom" /> 
    </clientCertificate> 
    <serviceCertificate findValue="XX XX XX XX XX XX XX XX XX XX" x509FindType="FindBySerialNumber" /> 
    </serviceCredentials> 
    </behavior> 
</serviceBehaviors> 
</behaviors> 
<extensions> 
<behaviorExtensions> 
    <add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/> 
</behaviorExtensions> 
</extensions> 

,这里的客户的app.config:

<system.serviceModel> 
<behaviors> 
    <endpointBehaviors> 
    <behavior name="NewBehavior"> 
    <clientCredentials> 
    <clientCertificate findValue="XX XX XX XX XX XX XX XX XX XX" x509FindType="FindBySerialNumber" /> 
    </clientCredentials> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 
<bindings> 
    <wsHttpBinding> 
    <binding name="App.AppM_NameEP" 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="false" /> 
    <security mode="Message"> 
    <transport clientCredentialType="None" proxyCredentialType="None" realm="" /> 
    <message clientCredentialType="Certificate" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" /> 
    </security> 
    </binding> 
    </wsHttpBinding> 
</bindings> 
<client> 
    <endpoint address="https://urlsegura/App/Appm_Name.svc" binding="wsHttpBinding" bindingConfiguration="App.AppM_NameEP" contract="App.IAppM_Name" name="App.AppM_NameEP"> 
    <identity> 
    <certificate encodedValue="XXXX" /> 
    </identity> 
    </endpoint> 
</client> 
</system.serviceModel> 

在此先感谢。 此致敬礼。

回答

2

我想你的错误是由于你在配置中使用基于消息的安全性而导致的。请尝试将其更改为Transport(在客户端和服务配置文件中),以便它使用SSL进行安全性处理而不是对消息进行加密。

如果您绝对必须也加密邮件,则可以使用TransportWithMessageCredential。希望有所帮助。

+0

谢谢,我想我会使用TransportWithMessageCredential,因为我需要通过证书分别识别我的客户。 – programadoral

0

我不明白您描述的反向代理,但似乎您试图支持来自HTTP & HTTPS的访问。为此,您需要添加第二个端点。你会配置该服务是这样的:

<wsHttpBinding> 
<binding name="ConfigEP"> 
    <security mode="Message"> 
    <message clientCredentialType="Certificate" /> 
    </security> 
</binding> 
<binding name="ConfigEPHttps"> 
    <security mode="TransportWithMessageCredential"> 
    <message clientCredentialType="Certificate" /> 
    </security> 
</binding> 
</wsHttpBinding> 

,这增加了新的端点:

<service behaviorConfiguration="App.AppM_NameBehavior" name="App.AppM_Name"> 
<endpoint address="" behaviorConfiguration="App.AppM_NameEPBehavior" 
    binding="wsHttpBinding" 
    bindingConfiguration="ConfigEP" 
    name="App.AppM_NameEP" 
    bindingNamespace="http://siteName/AppM_Name" 
    contract="App.IAppM_Name" /> 
<endpoint address="secure" behaviorConfiguration="App.AppM_NameEPBehavior" 
    binding="wsHttpBinding" 
    bindingConfiguration="ConfigEPHttps" 
    name="App.AppM_NameEPHttps" 
    bindingNamespace="http://siteName/AppM_Name" 
    contract="App.IAppM_Name" /> 
</service> 

还需要做出这种改变,以获得WSDL通过HTTPS:

<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> 
+0

谢谢!但有了这个新的端点,我需要配置我的IIS应用程序来启用SSL,对吧? – programadoral

+0

是的,如果您希望允许通过HTTP和HTTPS访问服务,则您肯定需要将IIS应用程序配置为使用SSL。虽然添加传输级别加密将使您的服务更安全,但如果您的安全要求仅满足消息级别加密,则从长远来看,如果不使用SSL,则需要较少的内存。 –