死在SOAP...

本文介绍了SOAP(Simple Object Access Protocol)协议的基本概念,详细解释了其四个核心组成部分:SOAP封装、编码规则、RPC表示及绑定方式,并阐述了这些部分的功能及其相互之间的独立性。

什么是SOAP,SOAP是什么

SOAP(Simple Object Access Protocol )简单对象访问协议是在分散或分布式的环境中交换信息的简单的协议,是一个基于XML的协议,它包括四个部分:

SOAP封装(envelop),封装定义了一个描述消息中的内容是什么,是谁发送的,谁应当接受并处理它以及如何处理它们的框架;

SOAP编码规则(encoding rules),用于表示应用程序需要使用的数据类型的实例;

SOAP RPC表示(RPC representation),表示远程过程调用和应答的协定;

SOAP绑定(binding),使用底层协议交换信息。   

虽然这四个部分都作为SOAP的一部分,作为一个整体定义的,但他们在功能上是相交的、彼此独立的。特别的,信封和编码规则是被定义在不同的XML命名空间(namespace)中,这样使得定义更加简单。

 

引用自http://www.dayanmei.com/blog.php/ID_270.htm

 

浅谈 SOAP

http://www.ibm.com/developerworks/cn/xml/x-sisoap/index.html

for (i = 0; i < size; i++) { ONVIF_DBPRINTF(MSG_NOTICE, "analytic config channel cycle curr is: %d\n", i); for (j = 0; j < MAX_CHM_NUM; j++) { if (profiles[j].channel == 0) { j = MAX_CHM_NUM; break; } else if (profiles[j].motion_support == 0 && profiles[j].tamper_support == 0 && profiles[j].crossed_support == 0) { j = MAX_CHM_NUM; break; } else if (profiles[j].channel == (i + 1)) { break; } } ONVIF_DBPRINTF(MSG_NOTICE, "analytic config channel j is: %d\n", j); if (j == MAX_CHM_NUM) { i--; continue; } if (profiles[j].motion_support || profiles[j].tamper_support || profiles[j].crossed_support) { ONVIF_DBPRINTF(MSG_NOTICE, "start create analytic config channel is %d\n", j); vaconf = &res->Configurations[i]; vaconf->UseCount = SOURCE_USER; snprintf(temp_str, LEN_INFO, VIDEO_ANALYTICS_NAME, profiles[j].channel); vaconf->Name = soap_strdup(soap, temp_str); snprintf(temp_str, LEN_INFO, VIDEO_ANALYTICS_TOKEN, profiles[j].channel); vaconf->token = soap_strdup(soap, temp_str); vaconf->AnalyticsEngineConfiguration = tMalloc(struct tt__AnalyticsEngineConfiguration); if (vaconf->AnalyticsEngineConfiguration == NULL) return SOAP_SVR_FAULT; bzero(vaconf->AnalyticsEngineConfiguration, sizeof(struct tt__AnalyticsEngineConfiguration)); vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule = profiles[j].motion_support + profiles[j].tamper_support + profiles[j].crossed_support; ONVIF_DBPRINTF(MSG_NOTICE, "num of supported analy module %d\n", vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule); vaconf->AnalyticsEngineConfiguration->AnalyticsModule = lMalloc(struct tt__Config, sizeof(struct tt__Config) * vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule); if (vaconf->AnalyticsEngineConfiguration->AnalyticsModule == NULL) return SOAP_FAULT; bzero(vaconf->AnalyticsEngineConfiguration->AnalyticsModule, sizeof(struct tt__Config) * vaconf->AnalyticsEngineConfiguration->__sizeAnalyticsModule); index = 0; if (profiles[j].motion_support) { /* AnalyticsModule-MyCellMotionModule*/ struct tt__Config *MotionAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]); snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_MOTION, profiles[j].channel); MotionAnalyticsModule->Name = soap_strdup(soap, temp_str); MotionAnalyticsModule->Type = soap_strdup(soap, "tt:CellMotionEngine"); MotionAnalyticsModule->Parameters = tMalloc(struct tt__ItemList); if (MotionAnalyticsModule->Parameters == NULL) return SOAP_FAULT; bzero(MotionAnalyticsModule->Parameters, sizeof(struct tt__ItemList)); MotionAnalyticsModule->Parameters->__sizeElementItem = 1; MotionAnalyticsModule->Parameters->__sizeSimpleItem = 1; // for hik motion detect support MotionAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * MotionAnalyticsModule->Parameters->__sizeSimpleItem); if (MotionAnalyticsModule->Parameters->SimpleItem == NULL) return SOAP_FAULT; bzero(MotionAnalyticsModule->Parameters->SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * MotionAnalyticsModule->Parameters->__sizeSimpleItem); MotionAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Sensitivity"); sensitivity = get_motion_sensitivity(i / 2 + 1); snprintf(temp_str, LEN_INFO, "%d", sensitivity); MotionAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str); /* for hik MD support */ MotionAnalyticsModule->Parameters->ElementItem = tMalloc(struct _tt__ItemList_ElementItem); if (MotionAnalyticsModule->Parameters->ElementItem == NULL) return SOAP_FAULT; bzero(MotionAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem)); MotionAnalyticsModule->Parameters->ElementItem->Name = soap_strdup(soap, "Layout"); /* celllayout */ struct tt__CellLayout *cellLayout = tMalloc(struct tt__CellLayout); if (cellLayout == NULL) return SOAP_FAULT; bzero(cellLayout, sizeof(struct tt__CellLayout)); sprintf(temp_str, "%d", CELL_LAYOUT_COLS); cellLayout->Columns = soap_strdup(soap, temp_str); sprintf(temp_str, "%d", CELL_LAYOUT_ROWS); cellLayout->Rows = soap_strdup(soap, temp_str); cellLayout->Transformation = tMalloc(struct tt__Transformation); if (cellLayout->Transformation == NULL) return SOAP_FAULT; bzero(cellLayout->Transformation, sizeof(struct tt__Transformation)); cellLayout->Transformation->Translate = tMalloc(struct tt__Vector); if (cellLayout->Transformation->Translate == NULL) return SOAP_FAULT; cellLayout->Transformation->Translate->x = tMalloc(float); cellLayout->Transformation->Translate->y = tMalloc(float); bzero(cellLayout->Transformation->Translate->x, sizeof(float)); bzero(cellLayout->Transformation->Translate->y, sizeof(float)); *(cellLayout->Transformation->Translate->x) = -1; *(cellLayout->Transformation->Translate->y) = -1; cellLayout->Transformation->Scale = tMalloc(struct tt__Vector); if (cellLayout->Transformation->Scale == NULL) return SOAP_FAULT; cellLayout->Transformation->Scale->x = tMalloc(float); cellLayout->Transformation->Scale->y = tMalloc(float); bzero(cellLayout->Transformation->Scale->x, sizeof(float)); bzero(cellLayout->Transformation->Scale->y, sizeof(float)); // 有效位数 *(cellLayout->Transformation->Scale->x) = 0.09f; *(cellLayout->Transformation->Scale->y) = 0.11f; t = get_xml((pFunOut)soap_out_tt__CellLayout, soap, "tt", NULL, "tt:CellLayout", (void *)cellLayout, 0, ""); MotionAnalyticsModule->Parameters->ElementItem->__any = t; t = NULL; index++; } if (profiles[j].tamper_support) { /* AnalyticsModule-MyTamperDetecModule*/ struct tt__Config *TamperAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]); snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_TAMPER, profiles[j].channel); TamperAnalyticsModule->Name = soap_strdup(soap, temp_str); TamperAnalyticsModule->Type = soap_strdup(soap, "tt:TamperEngine"); TamperAnalyticsModule->Parameters = tMalloc(struct tt__ItemList); if (TamperAnalyticsModule->Parameters == NULL) return SOAP_FAULT; bzero(TamperAnalyticsModule->Parameters, sizeof(struct tt__ItemList)); TamperAnalyticsModule->Parameters->__sizeElementItem = 2; TamperAnalyticsModule->Parameters->__sizeSimpleItem = 1; TamperAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * TamperAnalyticsModule->Parameters->__sizeSimpleItem); if (TamperAnalyticsModule->Parameters->SimpleItem == NULL) return SOAP_FAULT; bzero(TamperAnalyticsModule->Parameters->SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * TamperAnalyticsModule->Parameters->__sizeSimpleItem); TamperAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Sensitivity"); sensitivity = get_tamper_sensitivity(i / 2 + 1); snprintf(temp_str, LEN_INFO, "%d", sensitivity); TamperAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str); TamperAnalyticsModule->Parameters->ElementItem = lMalloc(struct _tt__ItemList_ElementItem, sizeof(struct _tt__ItemList_ElementItem) * TamperAnalyticsModule->Parameters->__sizeElementItem); if (TamperAnalyticsModule->Parameters->ElementItem == NULL) return SOAP_FAULT; bzero(TamperAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem)); /* Element 0 */ TamperAnalyticsModule->Parameters->ElementItem[0].Name = soap_strdup(soap, "Transformation"); struct tt__Transformation *Transformation = tMalloc(struct tt__Transformation); if (Transformation == NULL) return SOAP_FAULT; bzero(Transformation, sizeof(struct tt__Transformation)); Transformation->Translate = tMalloc(struct tt__Vector); if (Transformation->Translate == NULL) return SOAP_FAULT; Transformation->Translate->x = tMalloc(float); Transformation->Translate->y = tMalloc(float); bzero(Transformation->Translate->x, sizeof(float)); bzero(Transformation->Translate->y, sizeof(float)); *(Transformation->Translate->x) = -1; *(Transformation->Translate->y) = -1; Transformation->Scale = tMalloc(struct tt__Vector); if (Transformation->Scale == NULL) return SOAP_FAULT; Transformation->Scale->x = tMalloc(float); Transformation->Scale->y = tMalloc(float); bzero(Transformation->Scale->x, sizeof(float)); bzero(Transformation->Scale->y, sizeof(float)); *(Transformation->Scale->x) = 0.0002f; *(Transformation->Scale->y) = 0.0002f; t = get_xml((pFunOut)soap_out_tt__Transformation, soap, "tt", NULL, "tt:Transformation", (void *)Transformation, 0, ""); TamperAnalyticsModule->Parameters->ElementItem[0].__any = t; t = NULL; /* Element 1 */ TamperAnalyticsModule->Parameters->ElementItem[1].Name = soap_strdup(soap, "Field"); TamperAnalyticsModule->Parameters->ElementItem[1].__any = "<tt:PolygonConfiguration>" "<tt:Polygon>" "<tt:Point x=\"0\" y=\"0\" />" "<tt:Point x=\"0\" y=\"10000\"/>" "<tt:Point x=\"10000\" y=\"10000\"/>" "<tt:Point x=\"1000\" y=\"0\"/>" "</tt:Polygon>" "</tt:PolygonConfiguration>"; index++; } if (profiles[j].crossed_support) { /* AnalyticsModule-MylinecrossingModule*/ struct tt__Config *CrossedAnalyticsModule = &(vaconf->AnalyticsEngineConfiguration->AnalyticsModule[index]); // if (CrossedAnalyticsModule == NULL) // return SOAP_FAULT; // bzero(CrossedAnalyticsModule, sizeof(struct tt__Config)); snprintf(temp_str, LEN_INFO, MODULE_TOKEN, ANALYTICS_CROSSED, profiles[j].channel); CrossedAnalyticsModule->Name = soap_strdup(soap, temp_str); CrossedAnalyticsModule->Type = soap_strdup(soap, "tt:LineDetector"); CrossedAnalyticsModule->Parameters = tMalloc(struct tt__ItemList); if (CrossedAnalyticsModule->Parameters == NULL) return SOAP_FAULT; bzero(CrossedAnalyticsModule->Parameters, sizeof(struct tt__ItemList)); CrossedAnalyticsModule->Parameters->__sizeElementItem = 1; CrossedAnalyticsModule->Parameters->__sizeSimpleItem = 1; /* for Direction */ CrossedAnalyticsModule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * CrossedAnalyticsModule->Parameters->__sizeSimpleItem); if (CrossedAnalyticsModule->Parameters->SimpleItem == NULL) return SOAP_FAULT; bzero(CrossedAnalyticsModule->Parameters->SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * CrossedAnalyticsModule->Parameters->__sizeSimpleItem); CrossedAnalyticsModule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "Direction"); int direction = 2; float pt_coord[4] = {0.0f, 0.0f, 1000.0f, 1000.0f}; /* ret = get_crossed_info(channel, &direction, pt_coord); if (ret < 0) return SOAP_FAULT;*/ snprintf(temp_str, LEN_INFO, "%d", direction); CrossedAnalyticsModule->Parameters->SimpleItem[0].Value = soap_strdup(soap, temp_str); /* for Segments */ CrossedAnalyticsModule->Parameters->ElementItem = tMalloc(struct _tt__ItemList_ElementItem); if (CrossedAnalyticsModule->Parameters->ElementItem == NULL) return SOAP_FAULT; bzero(CrossedAnalyticsModule->Parameters->ElementItem, sizeof(struct _tt__ItemList_ElementItem)); CrossedAnalyticsModule->Parameters->ElementItem[0].Name = soap_strdup(soap, "Segments"); struct tt__Polyline *segmets = lMalloc(struct tt__Polyline, sizeof(struct tt__Polyline)); if (segmets == NULL) return SOAP_FAULT; bzero(segmets, sizeof(struct tt__Polyline)); segmets->__sizePoint = 2; segmets->Point = lMalloc(struct tt__Vector, sizeof(struct tt__Vector) * segmets->__sizePoint); if (segmets->Point == NULL) return SOAP_FAULT; bzero(segmets->Point, sizeof(struct tt__Vector) * segmets->__sizePoint); segmets->Point[0].x = &pt_coord[0]; segmets->Point[0].y = &pt_coord[1]; segmets->Point[1].x = &pt_coord[2]; segmets->Point[1].y = &pt_coord[3]; t = get_xml((pFunOut)soap_out_tt__Polyline, soap, "tt", NULL, "tt:polyline", (void *)segmets, 0, ""); ONVIF_DBPRINTF(MSG_NOTICE, "create polyline xml \n"); CrossedAnalyticsModule->Parameters->ElementItem->__any = t; t = NULL; index++; } vaconf->RuleEngineConfiguration = tMalloc(struct tt__RuleEngineConfiguration); if (vaconf->RuleEngineConfiguration == NULL) return SOAP_SVR_FAULT; bzero(vaconf->RuleEngineConfiguration, sizeof(struct tt__RuleEngineConfiguration)); if (profiles[j].motion_support) { result = get_motion_detect_region_info(i / 2 + 1); if (result == NULL) { ONVIF_DBPRINTF(MSG_ERROR, "get NULL result from json API"); return SOAP_SVR_FAULT; } json_recv = json_tokener_parse(result); free(result); if (is_error(json_recv)) { ONVIF_DBPRINTF(MSG_ERROR, "error parsing json: %s", json_tokener_errors[-(unsigned long)json_recv]); return SOAP_SVR_FAULT; } json_data = json_object_object_get(json_recv, "region_info"); if (json_data == NULL) { JSON_FREE(json_recv); ONVIF_DBPRINTF(MSG_ERROR, "json_parse module get NULL from LuCI"); return SOAP_SVR_FAULT; } md_region_tmp = get_motion_detect_cells(json_data); if (md_region_tmp == NULL) { JSON_FREE(json_recv); ONVIF_DBPRINTF(MSG_ERROR, "get active cells failed"); return SOAP_SVR_FAULT; } md_region = soap_strdup(soap, md_region_tmp); free(md_region_tmp); JSON_FREE(json_recv); vaconf->RuleEngineConfiguration->__sizeRule = 1; /* RuleEngineConfiguration */ vaconf->RuleEngineConfiguration->Rule = lMalloc(struct tt__Config, sizeof(struct tt__Config) * vaconf->RuleEngineConfiguration->__sizeRule); if (vaconf->RuleEngineConfiguration->Rule == NULL) return SOAP_FAULT; bzero(vaconf->RuleEngineConfiguration->Rule, sizeof(struct tt__Config) * vaconf->RuleEngineConfiguration->__sizeRule); /* MyMotionDetectorRule */ struct tt__Config *MotionRule = vaconf->RuleEngineConfiguration->Rule; snprintf(temp_str, LEN_INFO, RULE_TOKEN, ANALYTICS_MOTION, profiles[j].channel); MotionRule->Name = soap_strdup(soap, temp_str); MotionRule->Type = soap_strdup(soap, "tt:CellMotionDetector"); MotionRule->Parameters = tMalloc(struct tt__ItemList); if (MotionRule->Parameters == NULL) return SOAP_FAULT; bzero(MotionRule->Parameters, sizeof(struct tt__ItemList)); MotionRule->Parameters->__sizeElementItem = 0; MotionRule->Parameters->__sizeSimpleItem = 4; MotionRule->Parameters->SimpleItem = lMalloc(struct _tt__ItemList_SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * 4); if (MotionRule->Parameters->SimpleItem == NULL) return SOAP_FAULT; bzero(MotionRule->Parameters->SimpleItem, sizeof(struct _tt__ItemList_SimpleItem) * MotionRule->Parameters->__sizeSimpleItem); /* for hik MD support */ MotionRule->Parameters->SimpleItem[0].Name = soap_strdup(soap, "ActiveCells"); MotionRule->Parameters->SimpleItem[0].Value = md_region; MotionRule->Parameters->SimpleItem[1].Name = soap_strdup(soap, "MinCount"); MotionRule->Parameters->SimpleItem[1].Value = soap_strdup(soap, "5"); MotionRule->Parameters->SimpleItem[2].Name = soap_strdup(soap, "AlarmOnDelay"); MotionRule->Parameters->SimpleItem[2].Value = soap_strdup(soap, "1000"); MotionRule->Parameters->SimpleItem[3].Name = soap_strdup(soap, "AlarmOffDelay"); MotionRule->Parameters->SimpleItem[3].Value = soap_strdup(soap, "1000"); } } }为什么这个会陷入循环
10-25
@app.route('/send_email', methods=['POST']) def handle_send_email(): """接收前端请求并调用邮件函数""" try: data = request.get_json() print(data) sjr = data.get('sjr', '').strip() csr = data.get('csr', '').strip() tbbt = data.get('tbbt', '').strip() tbnr = data.get('tbnr', '').strip() fjr = data.get('fjr', 'IDS').strip() if not sjr or not tbbt or not tbnr: return jsonify({"success": False, "message": "缺少必要参数"}), 400 result = send_mail_soap(sjr=sjr, csr=csr, tbbt=tbbt, tbnr=tbnr, fjr=fjr) return jsonify(result) except Exception as e: return jsonify({"success": False, "message": f"服务器错误: {str(e)}"}), 500{'sjr': 'X2527715', 'csr': '', 'tbbt': '【健康报告】李婷 的体检数据 (2025/9/19)', 'tbnr': '\nimport requests import html import urllib3 # 忽略 SSL 警告 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) def send_mail_soap(sjr: str, csr: str, tbbt: str, tbnr: str, fjr: str): msgd = '''<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ManualSend_08 xmlns="http://tempuri.org/"> <strMailCode>{0}</strMailCode> <strFormUser>{5}</strFormUser> <strRecipients>{1}</strRecipients> <strCopyRecipients>{2}</strCopyRecipients> <strSubject>{3}</strSubject> <strBody>{4}</strBody> </ManualSend_08> </soap:Body> </soap:Envelope>''' try: # HTML 转义防止 XML 错误 tbnr = html.escape(tbnr) tbbt = html.escape(tbbt) msgc = msgd.format("QFhky2Qfy8g=", sjr, csr, tbbt, tbnr, fjr) headers = { "Host": "ids.cdn.corpnet.auo.com", "Content-Type": "text/xml; charset=utf-8", "Content-Length": str(len(msgc)), "SOAPAction": "http://tempuri.org/ManualSend_08" } response = requests.post( "https://ids.cdn.corpnet.auo.com/ids_ws/mail.asmx", data=msgc, headers=headers, verify=False ) if response.status_code == 200: return {"success": True, "message": "邮件发送成功!", "response": response.text} else: return {"success": False, "message": f"HTTP {response.status_code}", "response": response.text} except Exception as e: return {"success": False, "message": f"请求异常: {str(e)}"}为什么会没有收到邮件
09-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值