sbornstein2
asked on
Consuming Web API in C# Help Need Guru Here
Hello all,
I have a Web API that I am trying to do the following. I need to pass to it a MemoryStream and then some string params as follows:
In my controller I have:
public HttpResponseMessage Post(SharepointParameter spParameter)
{
var response = SharepointService.UploadSh arepointDo cument(spP arameter.F ile, spParameter.SitePath, spParameter.FileName);
return new HttpResponseMessage(HttpSt atusCode.C reated);
}
I then have this parameter class defined:
public class SharepointParameter
{
public SharepointParameter() { }
public SharepointParameter(Memory Stream File, string SitePath, string FileName)
{
this.File = File;
this.SitePath = SitePath;
this.FileName = FileName;
}
public MemoryStream File { get; set; }
public string SitePath { get; set; }
public string FileName { get; set; }
}
Something similar I did but without a stream just string and ints I then used Fiddler and the POST under composer I used the URL Route such as:
http://localhost:62011/api/Sharepoint/Sharepoint
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:62011
Content-Length: 83
and in Request Body passed the parameter this is from another app I have:
{
"Mode":"S",
"BillingGroupId":9,
"EndDate":"6/30/2014",
"InvoiceTypeId":1
}
Now I need to consume the sharepoint Web API I am building from an MVC application. So far I have this in my actionresult in the MVC app:
PdfGenerate pdf = new PdfGenerate();
MemoryStream ms = new MemoryStream();
ms = pdf.CreatePdf(id);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(WebConfigurationManage r.AppSetti ngs["Share pointWebAP IPath"]);
client.DefaultRequestHeade rs.Accept. Add(new System.Net.Http.Headers.Me diaTypeWit hQualityHe aderValue( "applicati on/json")) ;
So I have my Memory stream so now I am not sure how I pass the MemoryStream and two strings SitePath and FileName along with it. Can the stream also serialize in JSON etc? The file will be a PDF file.
I have a Web API that I am trying to do the following. I need to pass to it a MemoryStream and then some string params as follows:
In my controller I have:
public HttpResponseMessage Post(SharepointParameter spParameter)
{
var response = SharepointService.UploadSh
return new HttpResponseMessage(HttpSt
}
I then have this parameter class defined:
public class SharepointParameter
{
public SharepointParameter() { }
public SharepointParameter(Memory
{
this.File = File;
this.SitePath = SitePath;
this.FileName = FileName;
}
public MemoryStream File { get; set; }
public string SitePath { get; set; }
public string FileName { get; set; }
}
Something similar I did but without a stream just string and ints I then used Fiddler and the POST under composer I used the URL Route such as:
http://localhost:62011/api/Sharepoint/Sharepoint
User-Agent: Fiddler
Content-Type: application/json
Host: localhost:62011
Content-Length: 83
and in Request Body passed the parameter this is from another app I have:
{
"Mode":"S",
"BillingGroupId":9,
"EndDate":"6/30/2014",
"InvoiceTypeId":1
}
Now I need to consume the sharepoint Web API I am building from an MVC application. So far I have this in my actionresult in the MVC app:
PdfGenerate pdf = new PdfGenerate();
MemoryStream ms = new MemoryStream();
ms = pdf.CreatePdf(id);
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(WebConfigurationManage
client.DefaultRequestHeade
So I have my Memory stream so now I am not sure how I pass the MemoryStream and two strings SitePath and FileName along with it. Can the stream also serialize in JSON etc? The file will be a PDF file.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Can't you get the bytes from memory stream and pass it to your web api ? Check in this link where they are posting a memory stream in web request, http://www.andrescottwilson.com/posting-content-from-memory-stream-using-httpwebrequest-c/. Hope it helps.
ASKER
tx