WCF를 만드는 중입니다. 자바 스크립트에서 오는 json 객체를 POST 작업으로 쿼리 문자열로 저장하고 싶습니다. json 객체를 쿼리 문자열로 가져 오는 중입니다. 그것은 편안한 WCF에서이 도움을 주시기 바랍니다 액세스 ..........wcf를 사용하여 json 객체를 쿼리합니다. 편안한 서비스
내 자바 스크립트 코드
var myRequest = new XMLHttpRequest();
myRequest.onreadystatechange=function(dataString) {
if (myRequest.readyState == 4 && myRequest.status == 200) {
console.log('Sent to server: ' + dataString + '');
window.localStorage.removeItem(dataString);
}
else if (myRequest.readyState == 4 && myRequest.status != 200) {
console.log('Server request could not be completed');
saveDataLocally(dataString);
}
}
var url="http://localhost:58168/RestServiceImpl.svc/json";
myRequest.open("POST",url+"?"+dataString,true);
myRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
myRequest.send(dataString);
alert('Saved to server: ' + dataString + '');
내 요청 자바 스크립트
,[쿼리 스트링으로 JSON 오브젝트를 보내는로운 서버 WCF하면서] [1]
>**RequestURL**:http://localhost:58168/RestServiceImpl.svc/json?"firstName":"shuresh","lastName":"kumar"}
요청 헤더!가 콘텐츠 유형 : 애플리케이션/ 을 x-www-form-urlencoded를 원산지 : 크롬 확장 : // ddijiilbgbjgciahjmonfahapadmkcfp 사용자 에이전트 : 모질라/5.0 (윈도우 NT 6.1) AppleWebKit/537.36 (게코 같은 KHTML) 크롬/27.0.1453.116 사파리/537.36
쿼리 문자열 매개 변수 { "firstName을": "shuresh", "이 lastName": "쿠마"} :
양식 데이터 { "firstName을": "shuresh", "이 lastName": "쿠마"} :
WCF RESTful 서비스 계약
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "json?dataString={dataString}")]
string JSONData(string dataString);
RestServiceImpl.svc.cs
public string JSONData(string dataString)
{
return "You requested product " + dataString;
}
서비스 계약에서 json 개체 (dataString)에 액세스 할 수 없습니다. 위의 코드에서 위의 코드에서 querystring에 추가되는 json 개체에 액세스하는 방법을 알려주십시오.
http://localhost:58168/RestServiceImpl.svc/json?"firstName":"shuresh","lastName":"kumar"}