VC 通过HTTP调用webservice请求数据

lijianli9 2010-09-29 06:37:24
CHttpFile *pFile = m_pHttp->OpenRequest(CHttpConnection::HTTP_VERB_POST,
"/HelloWorldService/services/HelloWorld.asmx", NULL, 0, NULL, NULL, m_dwHttpRequestFlags);
pFile->AddRequestHeaders("Content-Type: text/xml; charset=utf-8", HTTP_ADDREQ_FLAG_ADD);
pFile->AddRequestHeaders("SOAPAction: \"http://tempuri.org/exampleMessage\"", HTTP_ADDREQ_FLAG_ADD);

strData += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strData += "\r\n<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/\">";
strData += "\r\n\t<soap:Body>";
strData += "\r\n\t\t<exampleMessage xmlns=\"http://tempuri.org/\">";
strData += "\r\n\t\t\t";
strData += SetXmlSection("in0", "hello", szXmlData);
strData += "\r\n\t\t";
strData += "</exampleMessage>";
strData += "\r\n\t</soap:Body>";
strData += "\r\n</soap:Envelope>";
webservice是我用java在tomcat上写的一个exampleMessage接口,但是调用的时候没有放回自己要的数据?请教高手如何解决这个问题?
java的webservice接口是http://localhost:8080/HelloWorldService/services/HelloWorld.asmx,里面有一个接口是exampleMessage 接受一个string参数。
...全文
306 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zyyoung 2010-10-21
  • 打赏
  • 举报
回复
没试过怎么知道
lijianli9 2010-10-10
  • 打赏
  • 举报
回复
senddata肯定要发的,
贪玩的老鼠 2010-10-09
  • 打赏
  • 举报
回复
你没有调用SendRequest发送你的strData
AddRequestHeaders
SendRequest
EndRequest
调用
QueryInfoStatusCode
判断是否正常返回
调用QueryInfo获取返回结果
lijianli9 2010-10-09
  • 打赏
  • 举报
回复
你这样是请求url页面数据的吧,和我的需求不一致哦,
zyyoung 2010-09-30
  • 打赏
  • 举报
回复

struct __FCAutoInitializeCOM
{
__FCAutoInitializeCOM() {CoInitialize(0);}
~__FCAutoInitializeCOM() {CoUninitialize();}
};

// encapsuled download thread.
DWORD JetWebService::httpGet(CString url,char *ret)
{
__FCAutoInitializeCOM _aAutoCOM ;

char * pBuf = NULL ;
int nBufLen = 0 ;
TRY
{
// connection
CInternetSession sess ;
sess.SetOption (INTERNET_OPTION_CONNECT_TIMEOUT, 30 * 1000) ;
sess.SetOption (INTERNET_OPTION_CONNECT_BACKOFF, 1000) ;
sess.SetOption (INTERNET_OPTION_CONNECT_RETRIES, 1) ;

DWORD dwFlag = INTERNET_FLAG_TRANSFER_BINARY|INTERNET_FLAG_DONT_CACHE|INTERNET_FLAG_RELOAD ;
CHttpFile * pF = (CHttpFile*)sess.OpenURL(url, 1, dwFlag); ASSERT(pF);
if (!pF)
{AfxThrowInternetException(1);}

// connection status
CString str ;
pF->QueryInfo (HTTP_QUERY_STATUS_CODE, str) ;

// Proxy Authentication Required
if (str == _T("407"))
{
CString strUsername, strPassword ;
pF->SetOption (INTERNET_OPTION_PROXY_USERNAME, (VOID*)(LPCTSTR)strUsername, strUsername.GetLength()) ;
pF->SetOption (INTERNET_OPTION_PROXY_PASSWORD, (VOID*)(LPCTSTR)strPassword, strPassword.GetLength()) ;
pF->SendRequest (NULL);
}

pF->QueryInfo (HTTP_QUERY_STATUS_CODE, str) ;
if (str != _T("200"))
{
pF->Close() ;
delete pF ;
AfxThrowInternetException(1);
}

// confirm update
pF->QueryInfo (HTTP_QUERY_LAST_MODIFIED, str) ;

// start download
pF->QueryInfo (HTTP_QUERY_CONTENT_LENGTH, str) ; // file's length

if (_ttoi(str))
{
// know file's size
int nLen = (nBufLen = _ttoi(str)) ;
char * p = (pBuf = new char[nLen+8]) ;
ZeroMemory (p, nLen+8) ;

// download 8K every
int n = pF->Read (p, (nLen < 8192) ? nLen : 8192) ;
p += n ; nLen -= n ;

// interrupted
if (nLen != 0)
{
delete[] pBuf; pBuf=NULL;
nBufLen = 0 ;
}
}

pF->Close() ;
delete pF ;
}
CATCH_ALL(e) {}
END_CATCH_ALL
if (pBuf)
{
memcpy(ret,pBuf,strlen(pBuf));
delete[] pBuf ;
}
return 0 ;
}

18,363

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧