user-0 提问: 怎么在c语言中用socket的方式调用webservice？？

回复:
user: user-1
content: 跟webservice无关，跟socket编程有关。 如果放着webservice的库不用，那么还是先从socket的编程的基本内容开始吧。

user: user-2
content: 可以实现，先connect sockaddr_in server; 	if (m_bSockConnected)  	{ 		return TRUE; 	} 	server.sin_addr.s_addr	= inet_addr(m_szHost); 	server.sin_family		= AF_INET; 	server.sin_port			= htons((UINT)m_nPort);  	if(connect(m_socket, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) 	{ 		m_bSockConnected = FALSE; 		m_nLastErrorNo = WSAGetLastError(); 		MessageBox(0, "请检网络和服务器", "网络连接错误", 0); 		return FALSE;  	} 	else 	{ 		m_bSockConnected = TRUE; 	}  	int timeout=30; 	setsockopt(m_socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(int)); 然后再发送url char requestHeader[1024]= {0}; 	char nBuf[36]			= {0}; 	strcpy(requestHeader, "PUT "); 	strcat(requestHeader, szUrl); 	strcat(requestHeader, "&Content-Length="); 	_ui64toa(contentLength + 8, nBuf,10); //额外加了传输完成头的长度是8 strlen(SEND_END_STRING) 	strcat(requestHeader, nBuf); 	strcat(requestHeader, "&FileCount="); 	ltoa(fileCount,nBuf, 10); 	strcat(requestHeader, nBuf); 	strcat(requestHeader," HTTP/1.1\r\nContent-Length: "); 	_ui64toa(contentLength + 8, nBuf, 10); 	strcat(requestHeader,nBuf); 	strcat(requestHeader,"\r\nHost: "); 	strcat(requestHeader,m_szHost); 	strcat(requestHeader,":"); 	itoa(m_nPort,nBuf,10); 	strcat(requestHeader,nBuf); 	strcat(requestHeader,"\r\nAccept: */*;\r\nAccept-Encoding: gzip,deflate\r\nKeep-Alive: 60000\r\nConnection: keep-alive\r\n\r\n"); 	//MessageBox(0, requestHeader, "info", 0); 	char * szUTF8 = NULL; 	BOOL	bRet  = FALSE; 	bRet = CCharTransLib::EncodeToUTF8(requestHeader,&szUTF8); 	if (bRet) 	{ 		if ( (int)strlen(szUTF8) != send(m_socket, szUTF8, strlen(szUTF8), 0)) 		{ 			m_nLastErrorNo = GetLastError(); 			bRet = FALSE; 		} 		if (szUTF8) 		{ 			delete []szUTF8; 			szUTF8 = NULL; 		} 	} 以上是从我工程里面摘的，可能有些变量楼主编译不过去，但基本思想就是这样的

user: user-0
content: 引用 1 楼 user-6 的回复:先会如何用 http 交谈, 剩下的就是拼接 soap 文档了.  是发送一段http报文过去吗？？？

user: user-3
content: 百度gsoap。

user: user-4
content: 用soapui工具来转换成需要的头文件和源文件  直接掉生成的接口

user: user-0
content: 引用 4 楼 robertbo 的回复:可以实现，先connect sockaddr_in server; 	if (m_bSockConnected)  	{ 		return TRUE; 	} 	server.sin_addr.s_addr	= inet_addr(m_szHost); 	server.sin_family		= AF_INET; 	server.sin_port			= htons((UINT)m_nPort);  	if(connect(m_socket, (struct sockaddr*)&server, sizeof(server)) == SOCKET_ERROR) 	{ 		m_bSockConnected = FALSE; 		m_nLastErrorNo = WSAGetLastError(); 		MessageBox(0, "请检网络和服务器", "网络连接错误", 0); 		return FALSE;  	} 	else 	{ 		m_bSockConnected = TRUE; 	}  	int timeout=30; 	setsockopt(m_socket, SOL_SOCKET, SO_RCVTIMEO, (const char*)&timeout, sizeof(int)); 然后再发送url char requestHeader[1024]= {0}; 	char nBuf[36]			= {0}; 	strcpy(requestHeader, "PUT "); 	strcat(requestHeader, szUrl); 	strcat(requestHeader, "&Content-Length="); 	_ui64toa(contentLength + 8, nBuf,10); //额外加了传输完成头的长度是8 strlen(SEND_END_STRING) 	strcat(requestHeader, nBuf); 	strcat(requestHeader, "&FileCount="); 	ltoa(fileCount,nBuf, 10); 	strcat(requestHeader, nBuf); 	strcat(requestHeader," HTTP/1.1\r\nContent-Length: "); 	_ui64toa(contentLength + 8, nBuf, 10); 	strcat(requestHeader,nBuf); 	strcat(requestHeader,"\r\nHost: "); 	strcat(requestHeader,m_szHost); 	strcat(requestHeader,":"); 	itoa(m_nPort,nBuf,10); 	strcat(requestHeader,nBuf); 	strcat(requestHeader,"\r\nAccept: */*;\r\nAccept-Encoding: gzip,deflate\r\nKeep-Alive: 60000\r\nConnection: keep-alive\r\n\r\n"); 	//MessageBox(0, requestHeader, "info", 0); 	char * szUTF8 = NULL; 	BOOL	bRet  = FALSE; 	bRet = CCharTransLib::EncodeToUTF8(requestHeader,&szUTF8); 	if (bRet) 	{ 		if ( (int)strlen(szUTF8) != send(m_socket, szUTF8, strlen(szUTF8), 0)) 		{ 			m_nLastErrorNo = GetLastError(); 			bRet = FALSE; 		} 		if (szUTF8) 		{ 			delete []szUTF8; 			szUTF8 = NULL; 		} 	} 以上是从我工程里面摘的，可能有些变量楼主编译不过去，但基本思想就是这样的  如果我用http get的方式发送报文，服务端返回的内容是怎么样的呢？？我还没弄懂怎么解析返回报文。

user: user-5
content: 建议楼主先学会使用抓包软件比如wireshark

user: user-6
content: 先会如何用 http 交谈, 剩下的就是拼接 soap 文档了.