2012-06-01 1 views
0

구성이 잘못되었습니다. 암호로 보호 된 보안을 IIS (아직 성취되지 않음)로 감싸려고하고 있는데 모든 종류의 예외가 발생합니다. 이번에는 보안 토큰이 잘못되었거나 잘못된 요소 예외가 발생합니다.보안을위한 WCF 구성이 작동하지 않음 : Throwing 보안 토큰에 대한 요청에 잘못되었거나 형식이 잘못된 요소가 있습니다.

HOST :

<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.0" /> 
    </system.web> 
    <system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"/> 
    </system.webServer> 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name ="WSHttpBinding_ISVC1"> 
     <security mode="Message"> 
      <message clientCredentialType="UserName" establishSecurityContext="false"/> 
     </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="SVCBehaviors"> 
      <serviceMetadata httpGetEnabled="true" /> 
      <serviceDebug includeExceptionDetailInFaults="false" /> 
      <serviceCredentials> 
      <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="blahblah.SVCValidator, TrademarkGlobal.Web"/> 
      </serviceCredentials> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    <services> 
     <service name="blahblah.SVC" 
     behaviorConfiguration="SVCBehaviors"> 
     <endpoint address="" binding="wsHttpBinding" 
    contract="blahblah.ISVC" name="WSHttpBinding_ISVC1"/> 
     <endpoint contract="IMetadataExchange" 
      binding="mexHttpBinding" address="mex"/> 
     </service> 
    </services> 
    </system.serviceModel> 
</configuration> 

CLIENT: 
    <system.serviceModel> 
    <bindings> 
     <wsHttpBinding> 
     <binding name="WSHttpBinding_ISVC1"> 
      <security mode="Message"> 
      <message clientCredentialType="UserName" establishSecurityContext="false"/> 
      </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 
    <client> 
     <endpoint address="http://localhost:64609/SVC.svc" binding="wsHttpBinding" 
      bindingConfiguration="WSHttpBinding_ISVC1" contract="ISVC"> 
     </endpoint> 
    </client> 
    </system.serviceModel> 

SVC 파일 (svc.svc) :

<%@ServiceHost Service="blahblah.SVC" %> 

본 서비스 (SVC & ISVC)이 지금의 기본 strin g를 돌려 여기 내 CONFIGS 있습니다.

SVCVALIDATOR.cs : 실행하는 데 사용

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.ServiceModel; 
using System.IdentityModel.Selectors; 
public class SVCValidator : UserNamePasswordValidator 
{ 
    public override void Validate(string userName, string password) 
    { 
     if (userName == null || password == null) 
     { 
      throw new ArgumentNullException(); 
     } 
     if (userName != "gooduser" && password != "goodpass") 
     { 
      throw new Exception("Incorrect Username or Password"); 
     } 
    } 
} 

컨트롤러 액션 :

public class SVCController : Controller 
{ 
    public ActionResult Index(string user = "bad", string pass = "bad") 
    { 
     using (SVCClient client = new SVCClient()) 
     { 
     //SVCClient client = new SVCClient("WSHttpBinding_ISVC"); 
     client.ClientCredentials.UserName.UserName = user; 
     client.ClientCredentials.UserName.Password = pass; 
     ViewBag.Message = client.Test(); 
     return View("RunningSVC"); 
     } 
    } 
} 
+0

나는이 오류가 기본적으로 서버를 컴파일 할 수 없다고 생각한다. 실제 오류 메시지를 보려면 * blahblah.SVC * 서비스의 URL로 이동하십시오. 거기에 뭐가 보이니? – McGarnagle

답변

3

당신은 서버에서 바인딩 구성을 사용하지 마십시오.

귀하의 구성은 이름이 있습니다

<bindings> 
     <wsHttpBinding> 
     <binding name ="WSHttpBinding_ISVC1"> 
     <security mode="Message"> 
      <message clientCredentialType="UserName" establishSecurityContext="false"/> 
     </security> 
     </binding> 
     </wsHttpBinding> 
    </bindings> 

을하지만, 엔드 포인트는 구성 이름을 참조하지 않습니다. 올바른 엔드 포인트는 다음과 같아야합니다

<endpoint address="" binding="wsHttpBinding" 
    contract="blahblah.ISVC" name="WSHttpBinding_ISVC1" bindingConfiguration="WSHttpBinding_ISVC1" /> 

그 문제를 해결 있으면 알려 주시기 바랍니다.

+1

새 예외 : { "요청한 서비스 'http : // localhost : 64609/SVC.svc'를 활성화 할 수 없습니다. 자세한 정보는 서버의 진단 추적 로그를 참조하십시오. 나는 이것이 앞으로 나아갈 것으로 생각한다. 앞으로 제공 : 서비스 인증서가 제공되지 않습니다. ServiceCredentials에 서비스 인증서를 지정하십시오. 나는 증명서를 원하지 않는다. – tehdoommarine

+1

암호를 보호하려면 인증서를 사용해야합니다. 메시지 수준 (사용자 설정) 또는 전송 중 하나 여야합니다 - http://msdn.microsoft.com/en-us/library/ms733775.aspx –

+1

참조 - http://blogs.msdn.com/b/pedram /archive/2007/10/05/wcf-authentication-custom-username-and-password-validator.aspx 여기에는 에 대한 작업 코드가 들어 있습니다. –

관련 문제