user-0 提问: gSOAP不能正确解析服务器返回的消息，是不是命名空间问题？

回复:
user: user-1
content: 太感谢了，我也遇到同样的这问题，返回为4

user: user-2
content: 太感谢了，我也遇到同样的这问题.

user: user-3
content: 楼主v5~赞一下楼主的分享精神

user: user-4
content: wenxy1  版主您好，我也遇到了和您一样的问题，解决不了，能告诉我您是怎么修改soap_in_tt_Capabilities()这个函数的吗？不胜感激

user: user-4
content: 按照wenxy1版主的方法进行程序修改，未能达到如期效果，但是wenxy1版主的解决方法给了一定启发，具体程序修改方法和原因进行下述整理，本人就是按照这种修改方法得到正确解析结果，仅供参考： 问题一、 soap_call___tds__GetCapabilities函数调用返回错误值是4，但是从网络上接收到的流和正确解析的流是一模一样的，也就是 说网络流没问题，但是解析错误，为此看了一下错误的地方，是在tt:Extension中的tt:DHCPv6中，也就是在tt:Extension中， 暂时用不到extension中的东西，就注释掉了几个调用的地方，就正常得到Capabilities，当然extension中是没有数据的。 1、soap_in_tt__NetworkCapabilitiesExtension函数  			//if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH) 			//	if (soap_in_PointerTott__NetworkCapabilitiesExtension2(soap, "tt:Extension", &a->Extension, "tt:NetworkCapabilitiesExtension2")) 			//	{	soap_flag_Extension--; 			//		continue; 			//	} 			 			//if (soap->error == SOAP_TAG_MISMATCH && !soap_peek_element(soap)) 			//{	if (a->__any == NULL) 			//	{	if (soap_blist___any == NULL) 			//			soap_blist___any = soap_new_block(soap); 			//		a->__any = (char *)soap_push_block(soap, soap_blist___any, sizeof(char)); 			//		if (a->__any == NULL) 			//			return NULL; 			//		soap_default_byte(soap, a->__any); 			//	} 			//	if (soap_in_byte(soap, "-any", a->__any, "xsd:byte")) 			//	{	a->__size++; 			//		a->__any = NULL; 			//		continue; 			//	} 			//} 			 2、soap_in_tt__Capabilities函数             //if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH) 			//	if (soap_in_PointerTott__CapabilitiesExtension(soap, "tt:Extension", &a->Extension, "tt:CapabilitiesExtension")) 			//	{	soap_flag_Extension--; 			//		continue; 			//	}

user: user-0
content: /* file: soapC.c */ SOAP_FMAC3 struct tt__Capabilities * SOAP_FMAC4 soap_in_tt__Capabilities(struct soap *soap, const char *tag, struct tt__Capabilities *a, const char *type) { 	size_t soap_flag_Analytics = 1; 	size_t soap_flag_Device = 1; 	size_t soap_flag_Events = 1; 	size_t soap_flag_Imaging = 1; 	size_t soap_flag_Media = 1; 	size_t soap_flag_PTZ = 1; 	size_t soap_flag_Extension = 1; 	if (soap_element_begin_in(soap, tag, 0, type)) 		return NULL; 	a = (struct tt__Capabilities *)soap_id_enter(soap, soap->id, a, SOAP_TYPE_tt__Capabilities, sizeof(struct tt__Capabilities), 0, NULL, NULL, NULL); 	if (!a) 		return NULL; 	soap_default_tt__Capabilities(soap, a); 	if (soap_s2string(soap, soap_attr_value(soap, "-anyAttribute", 0), &a->__anyAttribute, 0, -1)) 		return NULL; 	if (soap->body && !*soap->href) 	{ 		for (;;) 		{	soap->error = SOAP_TAG_MISMATCH; 			if (soap_flag_Analytics && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__AnalyticsCapabilities(soap, "tt:Analytics", &a->Analytics, "tt:AnalyticsCapabilities")) 				{	soap_flag_Analytics--; 					continue; 				} 			if (soap_flag_Device && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__DeviceCapabilities(soap, "tt:Device", &a->Device, "tt:DeviceCapabilities")) 				{	soap_flag_Device--; 					continue; 				} 			if (soap_flag_Events && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__EventCapabilities(soap, "tt:Events", &a->Events, "tt:EventCapabilities")) 				{	soap_flag_Events--; 					continue; 				} 			if (soap_flag_Imaging && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__ImagingCapabilities(soap, "tt:Imaging", &a->Imaging, "tt:ImagingCapabilities")) 				{	soap_flag_Imaging--; 					continue; 				} 			if (soap_flag_Media && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__MediaCapabilities(soap, "tt:Media", &a->Media, "tt:MediaCapabilities")) 				{	soap_flag_Media--; 					continue; 				} 			if (soap_flag_PTZ && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__PTZCapabilities(soap, "tt:PTZ", &a->PTZ, "tt:PTZCapabilities")) 				{	soap_flag_PTZ--; 					continue; 				} 			/* wenxy comment */ 			/* 			if (soap_flag_Extension && soap->error == SOAP_TAG_MISMATCH) 				if (soap_in_PointerTott__CapabilitiesExtension(soap, "tt:Extension", &a->Extension, "tt:CapabilitiesExtension")) 				{	soap_flag_Extension--; 					continue; 				} 			*/ 			if (soap->error == SOAP_TAG_MISMATCH) 				soap->error = soap_ignore_element(soap); 			if (soap->error == SOAP_NO_TAG) 				break; 			if (soap->error) 				return NULL; 		} 		if (soap_element_end_in(soap, tag)) 			return NULL; 	} 	else 	{	a = (struct tt__Capabilities *)soap_id_forward(soap, soap->href, (void*)a, 0, SOAP_TYPE_tt__Capabilities, 0, sizeof(struct tt__Capabilities), 0, NULL); 		if (soap->body && soap_element_end_in(soap, tag)) 			return NULL; 	} 	return a; }

user: user-5
content: 应该是带了html头的缘故吧。

user: user-6
content: 楼主，你的soap_in_tt_Capabilities()是如何修改的，能说说么？

user: user-0
content: I fix the issue: modify soap_in_tt__Capabilities() in soapC.c.  Over, :-).

user: user-0
content: 引用 4 楼 zxycele 的回复:楼主可不可以贴出完整的工程文件啊，我也在学习 抱歉，不行。

user: user-7
content: 楼主可不可以贴出完整的工程文件啊，我也在学习

user: user-0
content: 192.168.1.37的应答xml消息：  <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"  xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"  xmlns:ds="http://www.w3.org/2000/09/xmldsig#"  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"  xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include"  xmlns:wsbf2="http://docs.oasis-open.org/wsrf/bf-2"  xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"  xmlns:wsa5="http://www.w3.org/2005/08/addressing"  xmlns:tt="http://www.onvif.org/ver10/schema"  xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"  xmlns:wsr2="http://docs.oasis-open.org/wsrf/r-2"  xmlns:daae="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding"  xmlns:dare="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding"  xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"  xmlns:decpp="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding"  xmlns:dee="http://www.onvif.org/ver10/events/wsdl/EventBinding"  xmlns:denc="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding"  xmlns:denf="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"  xmlns:depp="http://www.onvif.org/ver10/events/wsdl/PullPointBinding"  xmlns:depps="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"  xmlns:tev="http://www.onvif.org/ver10/events/wsdl"  xmlns:depsm="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding"  xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"  xmlns:desm="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"  xmlns:dndl="http://www.onvif.org/ver10/network/wsdl/DiscoveryLookupBinding"  xmlns:dnrd="http://www.onvif.org/ver10/network/wsdl/RemoteDiscoveryBinding"  xmlns:d="http://schemas.xmlsoap.org/ws/2005/04/discovery"  xmlns:dn="http://www.onvif.org/ver10/network/wsdl"  xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl"  xmlns:tae="http://www.onvif.org/ver10/actionengine/wsdl"  xmlns:tds="http://www.onvif.org/ver10/device/wsdl"  xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"  xmlns:tls="http://www.onvif.org/ver10/display/wsdl"  xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"  xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"  xmlns:trc="http://www.onvif.org/ver10/recording/wsdl"  xmlns:trp="http://www.onvif.org/ver10/replay/wsdl"  xmlns:trt="http://www.onvif.org/ver10/media/wsdl"  xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl"  xmlns:tse="http://www.onvif.org/ver10/search/wsdl"  xmlns:tns1="http://www.onvif.org/ver10/topics"  xmlns:tnsn="http://www.eventextension.com/2012/event/topics"  xmlns:ter="http://www.onvif.org/ver10/error"  xmlns:xmime5="http://www.w3.org/2005/05/xmlmime"  xmlns:hikwsd="http://www.onvifext.com/onvif/ext/ver10/wsdl"  xmlns:hikxsd="http://www.onvifext.com/onvif/ext/ver10/schema"> <SOAP-ENV:Body> <tds:GetCapabilitiesResponse> <tds:Capabilities> 	<tt:Media> 		<tt:XAddr>http://192.168.1.37:80/onvif/services</tt:XAddr> 		<tt:StreamingCapabilities> 			<tt:RTPMulticast>false</tt:RTPMulticast> 			<tt:RTP_TCP>true</tt:RTP_TCP> 			<tt:RTP_RTSP_TCP>true</tt:RTP_RTSP_TCP> 		</tt:StreamingCapabilities> 	</tt:Media> </tds:Capabilities> </tds:GetCapabilitiesResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

user: user-0
content: 192.168.1.39.cap的应答xml消息  <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope  xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope"  xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:wsa5="http://www.w3.org/2005/08/addressing"  xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#"  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"  xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"  xmlns:ds="http://www.w3.org/2000/09/xmldsig#"  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"  xmlns:xmime5="http://www.w3.org/2005/05/xmlmime"  xmlns:xmime="http://tempuri.org/xmime.xsd"  xmlns:xop="http://www.w3.org/2004/08/xop/include"  xmlns:ns1="http://www.placeholder.org/ver10/tmp/schema"  xmlns:scdl="http://www.placeholder.org/ver10/scdl/schema"  xmlns:tt="http://www.onvif.org/ver10/schema"  xmlns:wsrf-bf="http://docs.oasis-open.org/wsrf/bf-2"  xmlns:wstop="http://docs.oasis-open.org/wsn/t-1"  xmlns:wsrf-r="http://docs.oasis-open.org/wsrf/r-2"  xmlns:scws="http://www.placeholder.org/ver10/scdl/wsdl"  xmlns:ns2="http://www.placeholder.org/ver10/tmp/wsdl"  xmlns:tae="http://www.onvif.org/ver10/actionengine/wsdl"  xmlns:tan0="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding"  xmlns:tan1="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding"  xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl"  xmlns:tds="http://www.onvif.org/ver10/device/wsdl"  xmlns:tev0="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding"  xmlns:tev1="http://www.onvif.org/ver10/events/wsdl/EventBinding"  xmlns:tev="http://www.onvif.org/ver10/events/wsdl"  xmlns:tev2="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding"  xmlns:tev3="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding"  xmlns:tev4="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding"  xmlns:tev5="http://www.onvif.org/ver10/events/wsdl/PullPointBinding"  xmlns:tev6="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding"  xmlns:ter="http://www.onvif.org/ver10/error"  xmlns:tns1="http://www.onvif.org/ver10/topics"  xmlns:tev7="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding"  xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2"  xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"  xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"  xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"  xmlns:trt="http://www.onvif.org/ver10/media/wsdl"> <SOAP-ENV:Body> <tds:GetCapabilitiesResponse> <tds:Capabilities> 	<tt:Media> 	<tt:XAddr>http://192.168.1.39/onvif/media_service</tt:XAddr> 	<tt:StreamingCapabilities> 	<tt:RTPMulticast>true</tt:RTPMulticast> 	<tt:RTP_TCP>true</tt:RTP_TCP> 	<tt:RTP_RTSP_TCP>true</tt:RTP_RTSP_TCP> 	</tt:StreamingCapabilities> 	<tt:Extension> 	<tt:ProfileCapabilities><tt:MaximumNumberOfProfiles>4</tt:MaximumNumberOfProfiles></tt:ProfileCapabilities> 	</tt:Extension> 	</tt:Media> <tt:Extension><tt:DeviceIO><tt:XAddr>http://192.168.1.39/onvif/deviceIO_service</tt:XAddr><tt:VideoSources>1</tt:VideoSources><tt:VideoOutputs>0</tt:VideoOutputs><tt:AudioSources>0</tt:AudioSources><tt:AudioOutputs>0</tt:AudioOutputs><tt:RelayOutputs>0</tt:RelayOutputs></tt:DeviceIO><tt:Extensions><tt:TelexCapabilities><tt:XAddr>http://192.168.1.39/onvif/scdl_service</tt:XAddr><tt:TimeOSDSupport>true</tt:TimeOSDSupport><tt:TitleOSDSupport>true</tt:TitleOSDSupport><tt:PTZ3DZoomSupport>true</tt:PTZ3DZoomSupport><tt:PTZAuxSwitchSupport>true</tt:PTZAuxSwitchSupport><tt:MotionDetectorSupport>true</tt:MotionDetectorSupport><tt:TamperDetectorSupport>true</tt:TamperDetectorSupport></tt:TelexCapabilities><tt:ScdlCapabilities><tt:XAddr>http://192.168.1.39/onvif/scdl_service</tt:XAddr><tt:MaximumNumberOfOSDs>4</tt:MaximumNumberOfOSDs><tt:PTZ3DZoomSupport>true</tt:PTZ3DZoomSupport><tt:TamperDetectorSupport>true</tt:TamperDetectorSupport></tt:ScdlCapabilities></tt:Extensions> </tt:Extension> </tds:Capabilities> </tds:GetCapabilitiesResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>

user: user-0
content: /* function onvif_get_capabilities source code as below: */ static int onvif_get_capabilities(struct soap *soap, char *soap_endpoint, char *soap_action) { 	int ret = 0; 	struct _tds__GetCapabilities getCapReq; 	struct _tds__GetCapabilitiesResponse getCapResponse; 	enum tt__CapabilityCategory  temp_category;  	pr_debug("Debug: into %s, %s\n", __FILE__, __FUNCTION__); /* wenxy debug */ 	if (soap == NULL || soap_endpoint == NULL || soap_endpoint == soap_action) 	{ 		return -EINVAL; 	} 	 	memset(&getCapReq, 0, sizeof(struct _tds__GetCapabilities)); 	memset(&getCapResponse, 0, sizeof(struct _tds__GetCapabilitiesResponse)); 	/*getCapReq.__sizeCategory = 1;*/ /* wenxy test ok */ 	/*temp_category = tt__CapabilityCategory__Media;*/ /* wenxy test ok */  	#if 1 	//getCapReq.__sizeCategory = 0; 	//temp_category = tt__CapabilityCategory__All; 	 	getCapReq.__sizeCategory = 1; 	temp_category = tt__CapabilityCategory__Media;	 	getCapReq.Category = &temp_category; 	#endif  	ret = soap_call___tds__GetCapabilities(soap, soap_endpoint, soap_action,  		&getCapReq, &getCapResponse); 	if (ret == -1) 	{ 		printf("ONVIF error: soap error: %d, %s, %s\n",  			soap->error, *soap_faultcode(soap), *soap_faultstring(soap)); 		ret = soap->error;     	} 	else 	{        		if (getCapResponse.Capabilities == NULL) 		{ 			printf("ONVIF error: GetCapabilities failed: %d, %s, %s, %s, %s\n",  				soap->error, *soap_faultcode(soap), *soap_faultsubcode(soap),  				*soap_faultstring(soap), *soap_faultdetail(soap));  		} 		else 		{ 			if (getCapResponse.Capabilities->Media) 			{ 				pr_debug("ONVIF: Media->XAddr=%s\n", getCapResponse.Capabilities->Media->XAddr); 				memset(media_service_addr_buf, 0, sizeof(media_service_addr_buf)); 				strcpy(media_service_addr_buf, getCapResponse.Capabilities->Media->XAddr); 			} 			if (getCapResponse.Capabilities->PTZ) 			{ 				pr_debug("ONVIF: PTZ->XAddr=%s\n", getCapResponse.Capabilities->PTZ->XAddr); 				memset(ptz_service_addr_buf, 0, sizeof(ptz_service_addr_buf)); 				strcpy(ptz_service_addr_buf, getCapResponse.Capabilities->PTZ->XAddr); 			} 			ret = 0; 		} 	}  	return ret; }  /* gSOAP namesapce */ SOAP_NMAC struct Namespace namespaces[] = { 	{"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://schemas.xmlsoap.org/soap/envelope/", NULL}, 	{"SOAP-ENC", "http://www.w3.org/2003/05/soap-encoding", "http://schemas.xmlsoap.org/soap/encoding/", NULL}, 	{"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL}, 	{"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL}, 	{"wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing", NULL, NULL}, 	{"wsdd", "http://schemas.xmlsoap.org/ws/2005/04/discovery", NULL, NULL}, 	{"chan", "http://schemas.microsoft.com/ws/2005/02/duplex", NULL, NULL}, 	{"wsa5", "http://www.w3.org/2005/08/addressing", "http://schemas.xmlsoap.org/ws/2004/08/addressing", NULL}, 	{"xmime", "http://tempuri.org/xmime.xsd", NULL, NULL}, 	{"xop", "http://www.w3.org/2004/08/xop/include", NULL, NULL}, 	{"wsrfbf", "http://docs.oasis-open.org/wsrf/bf-2", NULL, NULL}, 	{"wstop", "http://docs.oasis-open.org/wsn/t-1", NULL, NULL}, 	{"tt", "http://www.onvif.org/ver10/schema", NULL, NULL}, 	{"wsrfr", "http://docs.oasis-open.org/wsrf/r-2", NULL, NULL}, 	{"tad", "http://www.onvif.org/ver10/analyticsdevice/wsdl", NULL, NULL}, 	{"tan", "http://www.onvif.org/ver20/analytics/wsdl", NULL, NULL}, 	{"tdn", "http://www.onvif.org/ver10/network/wsdl", NULL, NULL}, 	{"tds", "http://www.onvif.org/ver10/device/wsdl", NULL, NULL}, 	{"tev", "http://www.onvif.org/ver10/events/wsdl", NULL, NULL}, 	{"wsnt", "http://docs.oasis-open.org/wsn/b-2", NULL, NULL}, 	{"timg", "http://www.onvif.org/ver20/imaging/wsdl", NULL, NULL}, 	{"tls", "http://www.onvif.org/ver10/display/wsdl", NULL, NULL}, 	{"tmd", "http://www.onvif.org/ver10/deviceIO/wsdl", NULL, NULL}, 	{"tptz", "http://www.onvif.org/ver20/ptz/wsdl", NULL, NULL}, 	{"trc", "http://www.onvif.org/ver10/recording/wsdl", NULL, NULL}, 	{"trp", "http://www.onvif.org/ver10/replay/wsdl", NULL, NULL}, 	{"trt", "http://www.onvif.org/ver10/media/wsdl", NULL, NULL}, 	{"trv", "http://www.onvif.org/ver10/receiver/wsdl", NULL, NULL}, 	{"tse", "http://www.onvif.org/ver10/search/wsdl", NULL, NULL}, 	{NULL, NULL, NULL, NULL} };