2011-08-18 113 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,則需要較少的內存。 –