I was wondering if anyone has had experience testing a WCF API with a SOAP Action, using Postman ?
This is also using OAuth2
I am trying to test using Postman but keep running up against a 401.
This is the same when I try SOAPUI.
I wrote a quick test in .Net using HttpClient and get the expected Response.
I am trying to create a collection to give to Client’s, rather than writing an app that has to be maintained etc…
using var client = new HttpClient();
// Request token
var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenEndpoint);
tokenRequest.Content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret)
});
var tokenResponse = await client.SendAsync(tokenRequest);
tokenResponse.EnsureSuccessStatusCode();
string tokenContent = await tokenResponse.Content.ReadAsStringAsync();
return Newtonsoft.Json.Linq.JObject.Parse(tokenContent)["access_token"]!.ToString();
API Request:
using var client = new HttpClient();
var apiRequest = new HttpRequestMessage(HttpMethod.Get, apiEndpoint);
apiRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
apiRequest.Headers.Add("SOAPAction", soapAction);
apiRequest.Headers.Add("ContentType", "application/xml");
apiRequest.Headers.Add("Accept", "text/xml");
apiRequest.Content = new StringContent(soapEnvelope, Encoding.UTF8, "text/xml");
var apiResponse = await client.SendAsync(apiRequest);
apiResponse.EnsureSuccessStatusCode();
return await apiResponse.Content.ReadAsStringAsync();
Could you try setting storing/copying the valid token, set the Auth Type to “No Auth” and then manually adding an Authorization Request Header instead?
Hi again Danny, I won’t say happy Monday, the only Monday that make us happy is a Bank Holiday Monday
So I created a small .Net app to interact with our API and then ran it with Fiddler polling for network traffic.
From this, I think it looks like the problem lies with how WCF authenticates, as well as OAUTH2, i.e.
The first request sends the SOAP envelope but gets 401 Unauthorized because the server requires authentication.
The second request is a simple POST that also gets 401, but this triggers the authentication mechanism.
The third request includes the correct Negotiate token and JWT—this is why it succeeds with 200 OK.
So I need to find out how I can get Postman to handle this sequence, hopefully without writing a script to do so.
Is this possible ? Even with a script, if not possible through the UI ?