webapiç¨çæ¯httpåè®®ï¼webserviceç¨çæ¯soapåè®®
webapiæ ç¶æï¼ç¸å¯¹webserviceæ´è½»é级ãwebapiæ¯æå¦get,postçhttpæä½
http soapå
³ç³»
http:æ¯ä¸ä¸ªå®¢æ·ç«¯åæå¡å¨ç«¯è¯·æ±ååºççæ åï¼TCPï¼ãhttpåè®®å
¶ç®çæ¯ä¸ºäºæä¾ä¸ç§åå¸åæ¥æ¶htttp页é¢çæ¹æ³
ä¸httpåè®®ç客æ·ç«¯ä¸æå¡å¨ç交äºï¼ç±HTTP客æ·ç«¯åèµ·ä¸ä¸ªè¯·æ±ï¼å»ºç«ä¸ä¸ªå°æå¡å¨æå®ç«¯å£ï¼é»è®¤æ¯80端å£ï¼çTCPè¿æ¥ãHTTPæå¡å¨åå¨é£ä¸ªç«¯å£çå¬å®¢æ·ç«¯åéè¿æ¥ç请æ±ãä¸æ¦æ¶å°è¯·æ±ï¼æå¡å¨ï¼å客æ·ç«¯ï¼ååä¸ä¸ªç¶æè¡ï¼æ¯å¦âHTTP/1.1 200 OKâï¼åï¼ååºçï¼æ¶æ¯ï¼æ¶æ¯çæ¶æ¯ä½å¯è½æ¯è¯·æ±çæ件ãé误æ¶æ¯ãæè
å
¶å®ä¸äºä¿¡æ¯ã
soap åè®®ï¼å®æè¿°äºä¸ç§å¨åæ£æåå¸å¼çç¯å¢ä¸å¦ä½äº¤æ¢ä¿¡æ¯çè½»é级åè®®ãsoapå¨httpåè®®çåºç¡ä¸ï¼ä¸ä¸ªåºäºXMLçåè®®ã
ä¸åï¼é½æ¯åºå±çéä¿¡åè®®ï¼è¯·æ±å
çæ ¼å¼ä¸åèå·²ï¼soapå
æ¯XMLæ ¼å¼,http纯ææ¬æ ¼å¼ã
å
³ç³»ï¼SOAPæ¯ä¸ªéä¿¡åè®®ï¼ SOAPå¨HTTPåè®®çåºç¡ä¸ï¼æç¼åæXMLçREQUESTåæ°, æ¾å¨HTTP BODYä¸æ交个WEB SERVICEæå¡å¨(SERVLETï¼ASPä»ä¹ç) å¤çå®æåï¼ç»æä¹åæXMLä½ä¸ºRESPONSEéåç¨æ·ç«¯ï¼ 为äºä½¿ç¨æ·ç«¯åWEB SERVICEå¯ä»¥ç¸äºå¯¹åºï¼å¯ä»¥ä½¿ç¨WSDLä½ä¸ºè¿ç§éä¿¡æ¹å¼çæè¿°æ件ï¼å©ç¨WSDLå·¥å
·å¯ä»¥èªå¨çæWSåç¨æ·ç«¯çæ¡æ¶æ件ï¼SOAPå
·å¤æå¤æ对象åºååæç»å°XMLéå»çè½åã
WCFåWEB APIæ该éæ©åªä¸ªï¼
1ãå½ä½ æ³å建ä¸ä¸ªæ¯ææ¶æ¯ãæ¶æ¯éåãåå·¥éä¿¡çæå¡æ¶ï¼ä½ åºè¯¥éæ©WCF
2ãå½ä½ æ³å建ä¸ä¸ªæå¡ï¼å¯ä»¥ç¨æ´å¿«éçä¼ è¾ééæ¶ï¼åTCPãNamed Pipesæè
çè³æ¯UDPï¼å¨WCF4.5ä¸ï¼,å¨å
¶ä»ä¼ è¾ééä¸å¯ç¨çæ¶åä¹å¯ä»¥æ¯æHTTPã
3ãå½ä½ æ³å建ä¸ä¸ªåºäºHTTPçé¢åèµæºçæå¡å¹¶ä¸å¯ä»¥ä½¿ç¨HTTPçå
¨é¨ç¹å¾æ¶ï¼æ¯å¦URIsãrequest/response头ï¼ç¼åï¼çæ¬æ§å¶ï¼å¤ç§å
å®¹æ ¼å¼ï¼ï¼ä½ åºè¯¥éæ©Web API
4ãå½ä½ æ³è®©ä½ çæå¡ç¨äºæµè§å¨ãææºãiPhoneåå¹³æ¿çµèæ¶ï¼ä½ åºè¯¥éæ©Web API
SOAPï¼Simple Object Access Protocol
ç®å对象访é®åè®®ï¼SOAPï¼æ¯ä¸ç§è½»éçãç®åçãåºäº XML çåè®®ï¼å®è¢«è®¾è®¡æå¨ WEB ä¸äº¤æ¢ç»æåçååºåçä¿¡æ¯ã SOAP å¯ä»¥åç°åç许å¤å ç¹ç½åè®®åæ ¼å¼ç»å使ç¨ï¼å
æ¬è¶
ææ¬ä¼ è¾åè®®ï¼ HTTPï¼ï¼ç®åé®ä»¶ä¼ è¾åè®®ï¼SMTPï¼ï¼å¤ç¨éç½é
é®ä»¶æ©å
åè®®ï¼MIMEï¼ãå®è¿æ¯æä»æ¶æ¯ç³»ç»å°è¿ç¨è¿ç¨è°ç¨ï¼RPCï¼ç大éçåºç¨ç¨åºã
HTTPåè®®ï¼ åºç¨å±
TCPåè®® ï¼ ä¼ è¾å±
HTTPå议详解ä¹ååºç¯
å¨æ¥æ¶å解é请æ±æ¶æ¯åï¼æå¡å¨è¿åä¸ä¸ªHTTPååºæ¶æ¯ã
HTTPååºä¹æ¯ç±ä¸ä¸ªé¨åç»æï¼åå«æ¯ï¼ç¶æè¡ãæ¶æ¯æ¥å¤´ãååºæ£æ
1ãç¶æè¡æ ¼å¼å¦ä¸ï¼
HTTP-Version Status-Code Reason-Phrase CRLF
å
¶ä¸ï¼HTTP-Version表示æå¡å¨HTTPåè®®ççæ¬ï¼Status-Code表示æå¡å¨ååçååºç¶æ代ç ï¼Reason-Phrase表示ç¶æ代ç çææ¬æè¿°ã
ç¶æ代ç æä¸ä½æ°åç»æï¼ç¬¬ä¸ä¸ªæ°åå®ä¹äºååºçç±»å«ï¼ä¸æäºç§å¯è½åå¼ï¼
1xxï¼æ示信æ¯â表示请æ±å·²æ¥æ¶ï¼ç»§ç»å¤ç
2xxï¼æåâ表示请æ±å·²è¢«æåæ¥æ¶ãç解ãæ¥å
3xxï¼éå®åâè¦å®æ请æ±å¿
é¡»è¿è¡æ´è¿ä¸æ¥çæä½
4xxï¼å®¢æ·ç«¯é误â请æ±æè¯æ³é误æ请æ±æ æ³å®ç°
5xxï¼æå¡å¨ç«¯é误âæå¡å¨æªè½å®ç°åæ³ç请æ±
常è§ç¶æ代ç ãç¶ææè¿°ã说æï¼
200 OK //客æ·ç«¯è¯·æ±æå
400 Bad Request //客æ·ç«¯è¯·æ±æè¯æ³é误ï¼ä¸è½è¢«æå¡å¨æç解
401 Unauthorized //请æ±æªç»ææï¼è¿ä¸ªç¶æ代ç å¿
é¡»åWWW-Authenticateæ¥å¤´åä¸èµ·ä½¿ç¨
403 Forbidden //æå¡å¨æ¶å°è¯·æ±ï¼ä½æ¯æç»æä¾æå¡
404 Not Found //请æ±èµæºä¸åå¨ï¼egï¼è¾å
¥äºé误çURL
500 Internal Server Error //æå¡å¨åçä¸å¯é¢æçé误
503 Server Unavailable //æå¡å¨å½åä¸è½å¤ç客æ·ç«¯ç请æ±ï¼ä¸æ®µæ¶é´åå¯è½æ¢å¤æ£å¸¸
egï¼HTTP/1.1 200 OK ï¼CRLFï¼
2ãååºæ¥å¤´åè¿°
3ãååºæ£æå°±æ¯æå¡å¨è¿åçèµæºçå
容
温馨提示:内容为网友见解,仅供参考