I have a service whereby I need to send a multipart response with different content types. I couldn't find any examples on how to do that with Nancy.
Is it supported in Nancy? If so, can you point me to an example?
There's nothing built in to do this so you'll have to construct your own Response type and/or corresponding Processor to build the multipart response.
Related
I am getting a post of Content-type Multipart/Related with an xml body with mainly PDF file attachments.
Is there a C# assembly that will handle the parsing of a post like this, where I can pull the attachments out with the purpose of saving them.
I have it done for Multipart/PostData, but it has to be for Multipart/Related.
Thanks
When you say "post", I get the feeling you are talking about an HTTP POST request?
Normally, for multipart/related (which tends to be email related), I would recommend my MimeKit library.
You could still use my MimeKit library to parse HTTP POST requests since MIME is MIME, but you could also take a look at Microsoft.AspNetCore.WebUtilities which has a MultipartReader class that will likely work great for this.
I have a 3rd party that is sending SOAP XML messages, as the HTTP message body (using HTTP Post). I need to write a program to accept / process these messages.
I have a specification document which contains 2 WSDL definitions - GetTransaction and CutOff.
I am trying to use Postman to send a test message. Content-Type is set to application/xml and the body is set to raw / XML.
I am using C#, ASP.Net (4.7.2), the code is in a Class Library. I have a Controller (ApiController) with:
[HttpPost]
[ValidationAttributes.RequireHttps]
public HttpResponseMessage Service(XmlDocument reqData)
but reqData is always null. I have tried different types instead of XmlDocument.
Now if probably a good time to say that this is all new to me - I've not created a program to accept SOAP messages before.
Should I be creating a WCF Service Application (rather than a .Net Framework Class Library)?
I've tried adding the WSDL "definitions" but they don't seem to produce anything useful. E.g. there is reference to a "GetTransaction" method, but it has a parameter list of about 150 items!?
I have found quite a lot of stuff via Google but it always seems to be about sending, rather than receiving, SOAP messages.
I appreciate that I have not really included much code to look at, but I feel like I've started from the wrong place. So, any basic guidance, suggestions or links to tutorial sites would be most welcome.
I have a GET API which returns an object of a particular class. I want to send additional information ( a number) without modifying the object in the response.
Following options came to my mind :
1) Using some header value and updating it and send the response(but I think that using headers would be a bad practice in this scenario).
2)Send a multipart response.
Thanks in advance!
If there is no way you can change the response and you need just simple data like numbers, it's OK to use HTTP headers in your response. You can see sample how to do paging using HTTP headers.
I'm getting a 406 error when trying to use RestSharp to post a request to a third-party application. I'm new to REST, so I have to admit I didn't even know you could add headers. I tried adding these, but I'm still getting the same issue:
var client = new RestClient(myURL);
RestRequest request = new RestRequest("restAction", Method.POST);
request.AddHeader("Accept", "text/plain");
request.AddHeader("Content-Type", "text/plain");
request.AddParameter("parameter1", param1);
request.AddParameter("parameter2", param2);
var response = client.Execute(request);
From what I've read, this may be dealing with a header named "accept". Is that right?
Any idea what could be going on?
In general in HTTP, when a client makes a request to a server, it tells the server what kinds of formats it's prepared to understand (accept). This list of acceptable formats is what the Accept header is for. If the server can't respond using any of the media types in the Accept header, it will return a 406. Otherwise, it will indicate which media type it chose in the Content-Type header of the response. Putting "*/*" in the Accept header tells the server that the client can handle any response media type.
In my original comment to your question, I said that RestSharp looks like it's including "*" in the Accept header by default, but looking closer I see now that it's actually not. So, if you don't override the Accept header like you've done here, the default header value is "application/json","application/xml","text/json","text/x-json","text/javascript","text/xml", and it appears the server you're talking to doesn't speak any of these media types.
If the server you're working with doesn't speak json or xml, I don't think you can use RestSharp, unless you create your own deserializer. I'm not sure if you can do this from the public API or if you'd have to modify the source yourself and recompile it for you own needs.
Since you're still getting HTTP errors from the server, I would recommend taking RestSharp out of the equation for right now, and just speaking HTTP directly to the server until you actually get a correct response from the server. You can use a tool like Fiddler to make a HTTP requests directly. When you send the request (for now in the debugging stage), send an Accept header of "*/*" to get around the 406. Once you've figured out what media types the server can send back to you, you should change this back to being a media type you know you can read and you know the server can send.
It sounds like the main issue here is really just not knowing the protocol of the server. If there's any documentation on the service you're talking to, I would read that very carefully to figure out what media types it's prepared to respond with and how to craft the URLs that it expects.
I am trying to extract the multipart attachment portion of a SOAP response.
I have a project that uses a Web Reference to talk to a 3rd party web service. I'm able to successfully make requests and get valid responses back from the service, but I don't understand where if anywhere the attachment data is going. Looking through the Web Reference autogenerated code there aren't any objects that match up to the actual attachment data.
Are there any kind options that I need to set when originally consuming the 3rd party WSDL to make this work correctly?
I had hoped there would be a .NET multipart boundary parser already, but wasn't able to find one so I wrote my own.
I have done this by getting the raw HTTP response as a string, splitting on the part boundaries ------=_Part_*. Then for each part looking for Content-Transfer-Encoding: base64, and then extracting the base 64 region and using Convert.FromBase64String to convert that to a byte array, and finally saving that as a file.