2016-01-31 35 views
5

服務器的App.config中:WCF:提供的URI方案'https'無效;預計'http'。參數名稱:通過當我打電話IInternal代理= factory.CreateChannel();在客戶端

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.web> 
    <compilation debug="true"/> 
    </system.web> 
    <system.serviceModel> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="NewBehaviour"> 
      <serviceMetadata httpsGetEnabled="True"/> 
      <serviceDebug includeExceptionDetailInFaults="True"/> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="Binding"> 
      <security mode="Transport"> 
      <transport clientCredentialType="None"></transport> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

    <services> 
     <service name="Server.InternalClass" behaviorConfiguration="NewBehaviour"> 
     <endpoint address="IInternal" binding="wsHttpBinding" bindingConfiguration="Binding" contract="Common.IInternal"> 
      <identity> 
      <dns value="MyMachine"/> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> 
     <host> 
      <baseAddresses> 
      <add baseAddress="https://MyMachine:8733/"/> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    </system.serviceModel> 


</configuration> 

客戶

static ChannelFactory<IInternal> factory = new ChannelFactory<IInternal>(new WSHttpBinding(), new EndpointAddress("https://MyMachine:8733/IInternal")); 

當我打電話的方法factory.CreateChannel(),我得到錯誤

我配置證書

enter image description here

+0

服務是否正確啓動?客戶端的app.config中的客戶端有什麼配置? –

+0

服務啓動正確。我沒有客戶端的配置文件。 – user3661837

回答

3

您必須告訴客戶端使用安全的傳輸通道,以便使用https而不是http。這是真實的,因爲客戶端的綁定設置必須與服務端的綁定設置相匹配。

您可以在客戶端的app.config文件通過配置做到這一點,或者你可以通過這樣的代碼做到這一點:

var ws_http_binding = new WSHttpBinding(); 

ws_http_binding.Security.Mode = SecurityMode.Transport; 

ChannelFactory<IInternal> factory = 
    new ChannelFactory<IInternal>(
     ws_http_binding, 
     new EndpointAddress("https://MyMachine:8733/IInternal")); 

var channel = factory.CreateChannel(); 
+0

非常感謝!有用! :)) – user3661837

+0

不客氣 –

相關問題