tags:

views:

76

answers:

1

I am using the MVC app as a service, so i have deleted the views. I am able to make calls to the controller:

public class HomeController : Controller
{
    // GET: /Home/
    public string Index(string param1, string param2) {
       ...
    }

from the MFC app:

string URL(_T("http://localhost:2374/home/index/myparam1/myparam2"));
pHttpFile = dynamic_cast<CHttpFile*> (m_Session.OpenURL(URL));
if (pHttpFile) {
    CHAR szBuff[1024] = { 0 };
    while (pHttpFile->Read(szBuff, 1024) > 0) {
        info += szBuff;
        ...

Now to upload an XML file, i am trying this on the MFC client:

CHttpConnection *pHttpConn = m_Session.GetHttpConnection(_T("localhost:2374"));
if (pHttpConn)
{
    CHttpFile *pHttpFile = pHttpConn->OpenRequest(
        CHttpConnection::HTTP_VERB_POST,
        _T("file.xml"));
    DWORD dwRet = 0;
    pHttpFile->QueryInfoStatusCode(dwRet);
    if (dwRet == HTTP_STATUS_OK)
    {
        CString headers(_T("Content-type: text/xml; charset=utf-8"));
        if (pHttpFile->AddRequestHeaders(headers))
        {
            if (pHttpFile->SendRequestEx(xml.GetLength(), HSR_SYNC | HSR_INITIATE))
            {
                pHttpFile->Write(xml, xml.GetLength());
                pHttpFile->EndRequest(HSR_SYNC);
                ...

and this on the MVC side:

    [AcceptVerbs(HttpVerbs.Post)]
    public void FileUpload(HttpPostedFileBase uploadFile)
    {

The client executes without error, but nothing happens on server side. I am not sure how to get FileUpload() called in the Controller. Do i use MapRoute(), if so how?

+1  A: 

There is no change nessecary on your server side.

The problem is the c++ client. The url you should call to upload the file is http://localhost:2374/home/fileupload. If the method fileupload is in the home controller. You don't need any other route for it.

I found a code sample for upload a file with winnet at code project http://www.codeproject.com/KB/library/lyoulhttpclient.aspx. I'm not a c++ guy, may be there are more. But this one looks good.

Christian13467
Yes, the problem indeed is in the client. Changing the 2nd parameter of OpenRequest() fixed the problem:CHttpFile *pHttpFile = pHttpConn->OpenRequest( CHttpConnection::HTTP_VERB_POST, _T("home/FileUpload"));Now Controller's FileUpload() gets called on SendRequest().Thanks to @Christian13467 and @bzlm.
amolbk