Android ksoap2 i:type suppression - android-ksoap2

I am trying to figure out how to suppress the i:type tag in the xml output generated by the ksoap2 library. I have tried the answers given in other posts but they have not worked. Does anyone have any ideas?
public static SoapObject createRequest() {
SoapObject method = new SoapObject(WS_NAMESPACE, WS_METHOD_NAME);
SoapObject request = new SoapObject("", "Request");
//Create source credentials object
SoapObject sourceCredentials = new SoapObject("", "SourceCredentials");
PropertyInfo sourceNameProp = new PropertyInfo();
//sourceNameProp.setNamespace(WS_NAMESPACE);
sourceNameProp.setName("SourceName");
sourceNameProp.setValue(SOURCENAME);
PropertyInfo passwordProp = new PropertyInfo();
//passwordProp.setNamespace(WS_NAMESPACE);
passwordProp.setName("Password");
passwordProp.setValue(PASSWORD);
sourceCredentials.addProperty(sourceNameProp);
sourceCredentials.addProperty(passwordProp);
SoapObject siteIds = new SoapObject("","SiteIDs");
PropertyInfo siteIDProp = new PropertyInfo();
//siteIDProp.setNamespace(WS_NAMESPACE);
siteIDProp.setName("int");
siteIDProp.setValue(SITE_IDS);
siteIds.addProperty(siteIDProp);
sourceCredentials.addSoapObject(siteIds);
request.addSoapObject(sourceCredentials);
PropertyInfo xMLDetailProp = new PropertyInfo();
//xMLDetailProp.setNamespace(WS_NAMESPACE);
xMLDetailProp.setName("XMLDetail");
xMLDetailProp.setValue("Full");
PropertyInfo pageSizeProp = new PropertyInfo();
//pageSizeProp.setNamespace(WS_NAMESPACE);
pageSizeProp.setName("PageSize");
pageSizeProp.setValue("10");
PropertyInfo curPageProp = new PropertyInfo();
//curPageProp.setNamespace(WS_NAMESPACE);
curPageProp.setName("CurrentPageIndex");
curPageProp.setValue("0");
request.addProperty(xMLDetailProp);
request.addProperty(pageSizeProp);
request.addProperty(curPageProp);
method.addSoapObject(request);
return method;
}
Then we create the envelope using code snippet below:
// 1. Create SOAP Envelope using the request
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.implicitTypes = true;
envelope.setAddAdornments(false);
envelope.setOutputSoapObject(parameter);
// 2. Create a HTTP Transport object to send the web service request
HttpTransportSE httpTransport = new HttpTransportSE(WSDL_URL);
httpTransport.debug = true; // allows capture of raw request/response in Logcat
// 3. Make the web service invocation
httpTransport.call(WS_NAMESPACE + "/" + WS_METHOD_NAME, envelope);
Output XML is below. Problem is the web service does not like the i:type fields on the Request and SourceCredentials nodes and I can't figure out how to suppress them. Can someone please help? Thanks.
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/"><v:Header />
<v:Body>
<GetLocations xmlns="http://clients.mindbodyonline.com/api/0_5">
<Request i:type=":Request">
<SourceCredentials i:type=":SourceCredentials">
<SourceName i:type="d:string">PilatesonCollins</SourceName>
<Password i:type="d:string">XGn2PaLeRoD8qoDtrZfODu8j71c=</Password>
<SiteIDs i:type=":SiteIDs">
<int i:type="d:int">25755</int>
</SiteIDs>
</SourceCredentials>
<XMLDetail i:type="d:string">Full</XMLDetail>
<PageSize i:type="d:string">10</PageSize>
<CurrentPageIndex i:type="d:string">0</CurrentPageIndex>
</Request>
</GetLocations>
</v:Body>
</v:Envelope>

You should set right type for each PropertyInfo:
propertyInfo.setType(value.getClass());.
In conjanction with envelope.implicitTypes = true; it will have effect.

Related

Attaching zip file is not working in WEB API, but works via POSTMAN

I have an .net core WEB API method that needs to call another external API (java) which expects .zip file. When try to access the external API via Postman by attaching the file, it is working fine (getting expected response). However when i pass the same parameters via my WEB API code, it is throwing 403-Forbidden error.
Please let me know if i am missing anything....
Thanks in advance!!!
request-header
request-body-file-attached
response-403-error
API code: for connecting to api:
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("pane", "forward");
parameters.Add("forward_path", "/store/execute");
parameters.Add("csrf", "1996fe6b2d0c97a8a0db725a10432d83");
parameters.Add("data_format", "binary");
newContent = new FormUrlEncodedContent(parameters);
MultipartFormDataContent form = new MultipartFormDataContent();
HttpContent con;// = new StringContent("file_name");
//form.Add(con, "file_name");
form.Add(newContent);
var str = new FileStream("D:\\dummy\\xmlstore.zip", FileMode.Open);
con = new StreamContent(str);
con.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
{
Name = "file_name",
FileName = "xmlstore.zip"
};
con.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
form.Add(con);
client.DefaultRequestHeaders.Add("Cookie", "JSESSIONID=05DEB277E294CBF73288F2E24682C7EE;");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("deflate"));
client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("br"));
client.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("user-agent", "1"));
var resp = client.PostAsync("java-api", con).Result;

Drupal 7 Service module node resources attach_file end point

I am implementing a Xamarin Form mobile app to allow post photo to Drupal using service module node resources. http://xxxx.com/{endpoint}/node/4/attach_file
i able to post from POSTMAN with
I tried to implement with c# HttpClient but keep getting response like "401 :Missing required argument field_name"
Please help on my code:
var httpClient = new HttpClient(new NativeMessageHandler());
httpClient.Timeout.Add(new TimeSpan(0, 0, 30));
httpClient.BaseAddress = new Uri(BaseAddress);
var content = new MultipartFormDataContent();
var streamContent = new StreamContent(g_media.GetStream());
streamContent.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse("form-data");
streamContent.Headers.ContentDisposition.Parameters.Add(new NameValueHeaderValue("field_name", "field_receipt_image"));
content.Add(streamContent,"files[file]");
var response = await httpClient.PostAsync("node/4/attach_file", content);
response.EnsureSuccessStatusCode();
I had the same issue and used RestSharp to resolve it. Here is the code I used to upload a file to Drupal:
var restClient = new RestClient("http:XXXXXX/attach_file");
var request = new RestRequest(Method.POST);
request.AddFile("files[file]", fileName);
request.AddParameter("field_name", field);
IRestResponse response = restClient.Execute(request);

SOAP in SWIFT import a Objective C Class

Hi I'm gonna code my application on xCode in Swift, before i had problems with my WebService SOAP in Android, so I did some search and they're a lot of subjects about, but my WebService is particular, look in Android what I did:
SSLConnection.allowAllSSL();
SoapObject request = new SoapObject(NAMESPACE, "SendLead");
request.addProperty("xml", xml);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportBasicAuth httpTransport = new HttpTransportBasicAuth(URL, getResources().getString(R.string.login), getResources().getString(R.string.mdp));
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
SoapObject result = (SoapObject) envelope.bodyIn;
Log.i(TAG, "Result Celsius: " + result);
SoapObject SendLeadReturn = (SoapObject) result.getProperty("SendLeadReturn");
String code = SendLeadReturn.getPropertyAsString("code");
So I have many constrains:
https URL
I have to keep my login to use the other functions of the wsdl (HttpTransportBasicAuth)
I send and receive xml strings
How to do it, I think it's preferable to import a Objective C class, but which and how please ?

restsharp AddParameter for POST not working on Mac (mono)

Using RestSharp 104.4.0 on Xamarin 4.2.2.
I cannot figure out why RestSharp does not add the parameter to a POST request. I am hitting a REST API that takes both GET and POST.
Not working POST:
var request_post = new RestRequest ("folder/endpoint.php", Method.POST);
request_post.AddParameter("ref", "some/value");
response = client.Execute(request_post);
Console.WriteLine (response.Content);
Error is saying that ref parameter is required.
Working GET:
var request_get = new RestRequest ("folder/endpoint.php", Method.GET);
request_get.AddParameter("ref", "some/value");
response = client.Execute(request_get);
Console.WriteLine (response.Content);
Update:
It may be adding the parameter but I need to add the parameters as a form.
Thanks, Matt.
// POST request.
//
// This method does not work!
// var request_post = new RestRequest ("folder/endpoint.php", Method.POST);
// request_post.AddParameter("ref", "some/value");
//
// This method does work.
var endpoint = String.Format("folder/endpoint.php?{0}={1}",
"ref", "some/value");
var request_post = new RestRequest (endpoint, Method.POST);
response = client.Execute(request_post);
// Print out headers.
foreach (var header in response.Headers){
Console.WriteLine(header);
}
// Print response.
Console.WriteLine(response.Content)

wp7 - twitter photo upload

We are trying to upload image to Twitter via silverlight code in WP7. We are able to post the message but not the image.
We tried all including download of their library but not getting the hint.
In following link,
https://dev.twitter.com/docs/api/1/post/statuses/update_with_media
there is one point which we are not able to set.
"Unlike POST statuses/update, this method expects raw multipart data. Your POST request's Content-Type should be set to multipart/form-data with the media[] parameter "
I am not getting it how to put it.
Can anyone please guide me or provide sample for image upload?
If your photo is called LoadedPhoto, you could create a memory stream from it
MemoryStream ms = new MemoryStream();
LoadedPhoto.SaveJpeg(ms, LoadedPhoto.PixelWidth, LoadedPhoto.PixelHeight, 0, 100);
Create OAuthCredentials object according to the authentication details you have acquired
var credentials = new OAuthCredentials
{
Type = OAuthType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
ConsumerKey = Common.TwitterSettings.ConsumerKey,
ConsumerSecret = Common.TwitterSettings.ConsumerKeySecret,
Token = file.AccessToken,
TokenSecret = file.AccessTokenSecret,
Version = "1.0"
};
Create a RestClient and a RestRequest
var restClient = new RestClient
{
Authority = "https://upload.twitter.com"
};
var restRequest = new RestRequest
{
Credentials = credentials,
Path = "/1/statuses/update_with_media.xml",
Method = Hammock.Web.WebMethod.Post
};
Set the stream position to 0
ms.Position = 0;
Add fields to RestRequest
restRequest.AddField("status", message);
restRequest.AddFile("media[]", "ScreenShot.png", ms, "image/jpeg");
And then begin request
restClient.BeginRequest(restRequest, callback);
callback is a callback method for the request.
Taken from my blog post, see there for more details if you're interested.

Resources