2012-06-12 4 views
1

전송 보안 모드를 사용하여 실행중인 basichttpbinding WCF 서비스가 있습니다. 이 잘 작동하지만이 서비스를 요청하는 사용자를 인증하고 싶습니다. 따라서 TransportWithMessagCredential의 보안 모드와 UserName의 clientCredentialType 메시지를 사용하고 사용자 지정 암호 유효성 검사기를 호출하는 서비스 동작을 추가하려고했습니다. 내 문제는 Visual Studio를 사용하여 참조를 호출하려고 할 때 서비스를 찾을 수 없다는 오류가 발생합니다. 아래에서 내 코드를 찾아서이 기능을 사용하기 위해 필요한 변경 사항을 제안하고 서비스를 추가 할 때 사용자 이름/암호를 묻습니다.사용자 이름/암호를 ssl webservice

의 Web.config

<?xml version="1.0"?> 
<configuration> 
<system.diagnostics> 
<sources> 
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" 
    propagateActivity="true"> 
    <listeners> 
     <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
     <filter type="" /> 
     </add> 
     <add initializeData="WcfTraces.svclog" type="System.Diagnostics.XmlWriterTraceListener" 
     name="traceListener"> 
     <filter type="" /> 
     </add> 
    </listeners> 
    </source> 
    <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing"> 
    <listeners> 
     <add type="System.Diagnostics.DefaultTraceListener" name="Default"> 
     <filter type="" /> 
     </add> 
     <add name="ServiceModelMessageLoggingListener"> 
     <filter type="" /> 
     </add> 
    </listeners> 
    </source> 
</sources> 
<sharedListeners> 
    <add initializeData="c:\users\**\web_messages.svclog" 
    type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral,  PublicKeyToken=***" 
    name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"> 
    <filter type="" /> 
    </add> 
</sharedListeners> 
</system.diagnostics> 
<system.serviceModel> 
<diagnostics> 
    <messageLogging logEntireMessage="true" logMalformedMessages="true" 
    logMessagesAtServiceLevel="false" logMessagesAtTransportLevel="true" /> 
</diagnostics> 
<bindings> 
    <basicHttpBinding> 
    <binding name="basicBindingConfig"> 
     <security mode="TransportWithMessageCredential"> 
     <transport clientCredentialType="None" /> 
     <message clientCredentialType="UserName" /> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<services> 
    <service behaviorConfiguration="ServiceBehavior" name="nameSpaceX.Service"> 
    <endpoint address="https://************:443/***.svc/" 
     binding="basicHttpBinding" bindingConfiguration="basicBindingConfig" 
     contract="nameSpaceY.IService"> 
     <identity> 
     <certificateReference x509FindType="FindByThumbprint" findValue="****************" /> 
     </identity> 
    </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" 
     httpsGetUrl="https://*****:443/***.svc" /> 
     <serviceDebug includeExceptionDetailInFaults="false" /> 
     <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" 
      customUserNamePasswordValidatorType="namespaceX.UserNameValidator, namespaceX" /> 
     </serviceCredentials> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
</system.serviceModel> 

</configuration> 

userNameValidator.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.IdentityModel.Selectors; 
using System.IdentityModel.Tokens; 

namespace namespaceX 
{ 
class UserNameValidator: UserNamePasswordValidator 
{ 
    public override void Validate(string username, string password) 
    { 
     if(username == "test" && password == "1234") 
      return; 
     throw new SecurityTokenException("Incorrect username or Password"); 
    } 
} 
} 
+1

"Visual Studio를 사용하여 참조를 호출하려고합니다."- 정확히 무엇을하고 오류 메시지 세부 정보를 명확히 할 수 있습니까? –

+0

기본적으로 브라우저에서 서비스를 탐색하려고하면 설명이 나타납니다. 설명 : HTTP 404. 찾고있는 리소스 (또는 해당 종속성 중 하나)가 제거되었거나 이름이 변경되었거나 일시적으로 사용할 수 없습니다. 다음 URL을 검토하고 철자가 올바른지 확인하십시오. 이것은 서비스에서 변경된 모든 것이 TransportwithMessageCredential과 위에서 설명한 서비스 동작을 사용하는 경우에 발생합니다. 전송 보안 만 사용할 때 제대로 작동합니다. 그러나 사용자 이름/암호로 보안을 설정해야합니다. –

+0

404를 볼 때 HTTPS : //...*.svc를 시도합니까? 정말 이상합니다. 보안은 엔드 포인트를 이동 시켜서는 안됩니다. –

답변

0

당신은 SVC는 여기 * 경로에 필요하지 않습니다. 일반적으로 httpsGetUrl 속성이 생략되거나 저장 ...? 여기 URL은 서비스 엔드 포인트에있는 것과 동일하다는 것을 전제로 들었다 WSDL

<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" 
    httpsGetUrl="https://*****:443/***.svc" /> 

. Ti는 하나의 구현이고 다른 하나는 메타 데이터이기 때문에 다른 URL이어야합니다.

+0

이것이 필요합니다. 그렇지 않으면 서비스를 만들 때 WCF가 도메인 이름 대신 컴퓨터 이름을 가리 킵니다. –

+0

내 대답이 업데이트되었습니다. –

+0

내 실수를 dsicovered. https : // ***** : 443/***. svc를 탐색 할 때 끝에 슬래시를 추가합니다. https : // ***** : 443/***. svc/그것을 깨뜨렸다. 정말 바보. 어쨌든 도움 주셔서 감사합니다. –