2012-06-05 223 views
1

我想用wsHTTPBinding和使用自定義用戶名來設置一個簡單的WCF Web服務。 我在遠程服務器設置上有服務,在另一個端口上有自簽名證書。 例如:https://service.myserice.com:442/service1.svcWCF客戶端安全默認爲Windows

出於某種原因,客戶端似乎默認爲Windows安全,即使我把它設置爲用戶名安全。

這裏是我的Web服務配置文件:

<configuration> 
<system.web> 
<compilation debug="true" targetFramework="4.0" /> 
<customErrors mode="Off"></customErrors> 
</system.web> 
<system.serviceModel> 
<services> 
    <service name="AutoSenderWCF.Service1" behaviorConfiguration="Behavior1"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="https://service.autosender.com.au:442/" /> 
     </baseAddresses> 
    </host> 
    <endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint> 
    <endpoint address="mex" 
     binding="mexHttpBinding" 
     contract="IMetadataExchange" /> 
    </service> 

</services> 
<bindings> 
    <wsHttpBinding> 
    <binding name="TransportBinding"> 
     <security mode="TransportWithMessageCredential">    
     <message clientCredentialType="UserName" />    
     </security>   
    </binding>   
    </wsHttpBinding>  
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="Behavior1"> 
     <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --> 
     <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/> 
     <!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information --> 
     <serviceDebug includeExceptionDetailInFaults="true"/> 

     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="AutoSenderWCF.CustomValidator, AutoSenderWCF"/> 

     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> 

和我的客戶端代碼(諾蒂奇醚:安全=窗口)

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <wsHttpBinding> 
       <binding name="TransportBinding_IService1" 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="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
        </security> 
       </binding> 
      </wsHttpBinding> 
     </bindings> 
     <client> 
      <endpoint address="http://service.autosender.com.au/Service1.svc" 
       binding="wsHttpBinding" bindingConfiguration="TransportBinding_IService1" 
       contract="ServiceReference1.IService1" name="TransportBinding_IService1"> 
       <identity> 
        <servicePrincipalName value="host/wserver" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 
+0

配置是在客戶端和服務器不同。你的問題是什麼? –

回答

0

我相信我已經解決了它: 這一行。

<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint> 

它不應該是bindingName應該bindingConfiguration

1

這是明確指定編輯在您的客戶端配置中使用Windows:

<security mode="Message"> 
         <transport clientCredentialType="Windows" proxyCredentialType="None" 
          realm="" /> 
         <message clientCredentialType="Windows" negotiateServiceCredential="true" 
          algorithmSuite="Default" /> 
        </security> 

從Server config複製該節。

+0

是的,但問題是我通過SVC Util創建配置..所以我不知道它爲什麼這樣創建它? – michael

+0

您是否嘗試更新服務參考?客戶端是否可以使用MEX端點?也許只有WSDL沒有這個信息。 –

+0

是的。我徹底刪除它,然後再試一次。 – michael