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.
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'm currently working on a client that has more features than another existing client for a game. One of the functionalities I would like to add is the ability for a user to add an IP address to their favourites and display relevant information of that server (IP, Port, Hostname, Gamemode etc.).
In order to do this I use an API which takes several parameters, such as the IP address and port. It returns some kind of string which contains the information that I need. However I'm having trouble extracting the information I want from the string. I did manage to do it, but I did it quick and dirty by using a dozen substrings to cut out the values of the parameters from the response.
Here's an example of an API call: http://monitor.sacnr.com/api/?IP=149.202.89.123&Port=7777&Action=info
Initially I thought the response was some kind of JSON string, but after some googling I found a question on Stackoverflow about stdClass. Apparently it's some kind of generic PHP class.
So my question is: how can I convert the response of the API to say JSON or XML, so I can easily parse it?
Example response:
O:8:"stdClass":18:{s:8:"ServerID";s:7:"1780392";s:2:"IP";s:14:"149.202.89.123";s:4:"Port";s:4:"7777";s:8:"Hostname";s:32:"Next Generation Roleplay (0.3.7)";s:8:"Gamemode";s:14:"NG:RP v3.0.409";s:8:"Language";s:7:"English";s:3:"Map";s:13:"NG-Gaming.net";s:10:"MaxPlayers";s:3:"500";s:7:"Players";s:3:"131";s:7:"Version";s:8:"0.3.7-R2";s:8:"Password";s:1:"0";s:4:"Time";s:5:"20:00";s:6:"WebURL";s:13:"ng-gaming.net";s:4:"Rank";s:3:"112";s:10:"AvgPlayers";s:5:"88.27";s:9:"HostedTab";s:1:"1";s:10:"LastUpdate";s:10:"1486138780";s:12:"TotalServers";s:4:"1305";}
Try using the Sharp Serialization Library.
As per their description: "Sharp Serialization Library serializes and deserializes primitives, ArrayLists and Hashtables, compatible with PHP serialize()"
After searching in google and here, i saw the popular approach is to convert the image to byte array and then to base64 string. this part was easy, but sending it and receiving it over HTTP is harder, and I can't find an easy way to do it.
I have 2 main question which depend one another
Send with android on HTTP:
Android 6 deprecated HttpClient, so i don't want to use that.
I thought to use Volley but i cant figure out how to make it work right.
Can you please give me an example of code to transfer it in a simple and elegant way which will be easy to intercept with C#?
Receive with C# and use of web service:
I'm not sure what is the best way to implement it? Should I create a web service method? in case i should, how can i intercept the post request? Should I create a new page to handle only this part. this way i know how to handle the request.
Edit:
I managed to create a request using HttpClient, but the base64 string after converting the file made the URI too long.
any other ideas?
I found here a post for uploading files from Android to ASP.NET Web API. However the HTTPClient was used for handling HTTP request but I think you can use code as reference.
Found the simple and elegant solution i wanted!
I use loopj library, "android-async-http" for sending files with 3-4 lines.
Then i get the request to a new aspx file in my ASP.NET server, and save it using "Request.Files" object.
I have an XML document that is encrypted using a proprietary encryption program like so:
exec($programName, $outputArr, $returnVal);
The resulting array ($outputArr) was serialized and stored as a blob in MySQL. I was making this encrypted array available on demand through a web interface. Basically deserializing and writing to a file on the fly.
Now the requirements have changed and I need to make this encrypted array available to another server which uses .net/c# and which in turn will host the web interface. We are using a REST API that responds to a GET request and sends out an XML response.
I tried writing the array into a temporary file and then retrieving the contents of the file using file_get_contents($tempFile) and then URL encoding the resulting string and putting that inside of the XML response that I was sending.
Of course, when the new web interface writes this out as a file (after URL decoding), it's nothing like it's supposed to be. By that, I mean our proprietary program throws up errors on reading this new resulting file ... somewhere along the way, there's data corruption happening.
We also tried a C# serialization library that deserialized PHP arrays into a c# primitive type but that wasn't a good solution either as it kept throwing up a bunch of errors.
Is there a better way to do this?
Why not just access the working version, and re-manipulate it before sending to the new server...
<!-- Some XML based wrapper or other logic/output -->
<?php
echo file_get_contents($url_to_working_web_interface);
?>