2010-11-19 3 views
0

사용 중 Visual Studio 및 MS CRM에 액세스하기 위해 원격 서버에 로그인했습니다. 나는 SDK에서 샘플 코드를 촬영하고 코드 실행하려고 한 :MS crm 계정 생성 : System.Net.WebException : 요청이 HTTP 상태 401 : Unauthorized로 실패했습니다.

CrmAuthenticationToken token = new CrmAuthenticationToken(); 

token.AuthenticationType = 0; 

token.OrganizationName = "AdventureWorksCycle"; 

CrmService service = new CrmService(); 
service.Url= "http://10.16.16.205:5555/mscrmservices/2007/crmservice.asmx"; 
service.CrmAuthenticationTokenValue = token; 

service.Credentials = new System.Net.NetworkCredential"username", "password", "domain"); 

// Create the account object. 
account account = new account(); 

// Set the properties of the account object. 
account.name = "Fourth Coffee123"; 
account.address1_line1 = "29 Market St."; 
account.address1_city = "Sam"; 
account.address1_stateorprovince = "MT1"; 
account.address1_postalcode = "9999"; 
account.donotbulkemail = new CrmBoolean(); 
account.donotbulkemail.Value = true; 

// Create the target object for the request. 
TargetCreateAccount target = new TargetCreateAccount(); 

// Set the properties of the target object. 
target.Account = account; 

// Create the request object. 
CreateRequest create = new CreateRequest(); 

// Set the properties of the request object. 
create.Target = target; 

// Execute the request. 
CreateResponse created = (CreateResponse)service.Execute(create); 

나는 이것에 대한 CRM을 웹 서비스를 사용하고, 그러나 그것의 던지는 예외 :

예외 정보 :

System.Net.WebException: The request failed with HTTP status 401: Unauthorized.

Source Error:

Line 114: [return: System.Xml.Serialization.XmlElementAttribute("Response")]

Line 115: public Response Execute(Request Request) {

210 Line 116: ***object[] results = this.Invoke("Execute", new object[]* {**

Line 117: Request});는 누락 Line 118: return ((Response)(results[0]));

답변

0

것은 실제 사용자 이름과 암호입니다. 나는이 질문의 목적을 위해 이것을 생략했다고 가정합니다.

웹 서비스 호출에 사용중인 사용자의 보안 역할을 확인 했습니까? 이 사용자를 아직 시스템 관리자 역할에 추가하지 않은 경우이 사용자를 시스템 관리자 역할에 추가하십시오.

종종 CRM을 사용하면이 오류는 보안과는 아무런 관련이 없지만 완전히 다른 것입니다.

먼저 CRM 추적을 켜고 거기를보십시오. 이렇게하면 더 자세한 오류 정보를 얻을 수 있습니다. 방법은 다음과 같습니다. http://support.microsoft.com/kb/907490

오류에 대한 자세한 내용을 보려면 예외 기록기를 사용해보십시오. 이것은 예외를 포맷하고 stdout이나 http 응답으로 출력 할 수있게 해주는 확장 클래스입니다. 여기 찾기 : http://paste.ly/5Y66

이이 방법을 사용 : 포맷 예외 출력에, 당신은 "세부 사항"속성은 텍스트 버전을 볼 수 있도록 직렬화 볼 수

try { 
    // do all your stuff 
} catch (Exception ex) { 
    ex.Print(); 
} 

알 수 있습니다. 이것은 CRM이 대부분의 시간에 실제 예외를 숨기는 곳입니다.

관련 문제