2014-04-18 4 views
1

나는 간단한 각도 응용 프로그램을 가지고 있습니다. 간단한 인증 방법이 있습니다. 메서드가 Internet Explorer에서 실행될 때 WCF 메서드는 데이터와 함께 인수를받습니다. ame 코드가 firefox에서 실행되면 인수는 서버에서 null입니다.

$http({ 
    url: Url, 
    method: "POST", 
    headers: { 
     'Content-Type': 'application/json; charset=utf-8' 
    }, 
    data: AuthenticateRequest 
}); 

WCF 방법

[WebInvoke(RequestFormat = WebMessageFormat.Json, 
    ResponseFormat = WebMessageFormat.Json, 
    Method = "*", 
    BodyStyle = WebMessageBodyStyle.Bare)] 
    [OperationContract] 
    AuthenticateResponse Authenticate(AuthenticateRequest AuthenticateRequest); 

피들러 IE 정보

POST http://www.api.com:56586/V1/Service.svc/json/Authenticate HTTP/1.1 
X-Requested-With: XMLHttpRequest 
Accept: application/json, text/plain, */* 
Content-Type: application/json; charset=utf-8 
Referer: http://www.api.com:54567/ 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko 
Host: localhost:56586 
Content-Length: 45 
DNT: 1 
Connection: Keep-Alive 
Pragma: no-cache 

{"UserName":"username","Password":"password"} 

파이어 폭스 피들러 정보

OPTIONS http://www.api.com:56586/V1/Service.svc/json/Authenticate HTTP/1.1 
Host: www.api.com:56586 
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0 
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language: en-US,en;q=0.5 
Accept-Encoding: gzip, deflate 
Origin: http://www.api.com:54567 
Access-Control-Request-Method: POST 
Access-Control-Request-Headers: content-type,x-requested-with 
Connection: keep-alive 
Pragma: no-cache 
Cache-Control: no-cache 
+0

FF가'POST '대신'OPTIONS' 요청을 보냅니다. 따라서 페이로드를 얻지 못합니다. 웹 응용 프로그램과 웹 서비스를 동일한 호스트/포트에서 호스팅합니까? 브라우저 자바 스크립트 콘솔에 어떤 정보가 있습니까? – Sebastian

답변

0

나는이 자바 스크립트 객체를 stringfy이 - 보내고 수행 얻을 수 있었다.

Service.js 

     angular.module('myModule').factory('serviceFac', ['$http', '$q', 
function (a, b) 
    { var taskMergeServiceNameSet = "WebServuice.svc/Tasks/SetTasks"; 
      return { 
       setTasksMerge: function (taskIds, action) { 

       var objArray = ''; 
       var obj = { 
         taskIds: taskIds, 
         action: action, 
         userName: "ss" 
        }; 
       objArray = new Array(); 
       objArray.push(obj); 
       var deferred = b.defer(); 
       a({ 
        url: taskMergeServiceNameSet, 
        method: 'POST', 
        headers: { 'Content-Type':'application/json; charset=utf-8'}, 
        data: JSON.stringify(objArray) 
        } 
       ).sucess(function (data) { deferred.resolve(data) }) 
        .error(function (msg, code) { deferred.reject(msg) });  
        return deferred.promise; 
       } 
      } 
     }]); 

서비스 계약

ServiceContract Interface 

[ServiceContract] 
public interface ITasks 
{ 
    [OperationContract] 
    [WebInvoke(Method = "POST",RequestFormat=WebMessageFormat.Json , 
     ResponseFormat = WebMessageFormat.Json, 
     UriTemplate = "Tasks/SetTasksForMerge")] 
    string CreateNewTaks(valObj[] values);   
} 

[DataContract] 
public class valObj 
    { 
    [DataMember] 
    public string taskIds { get; set; } 
    [DataMember] 
    public string action { get; set; } 
    [DataMember] 
    public string userName { get; set; } 
    } 

포스트 here는 나에게 많은 도움이되었습니다. JSON 문자열을 넘겨 주시면 알려주세요

관련 문제