WCF IClientMessageInspector and the incoming SOAP headers - c#

I'm responsible for updating a client-side API using WCF. This is because of changes to the API on the server (an outside company). When I get the response, my client-side throws an exception. Using Fiddler, I came up with the following problem: a duplicate Content-Type.
HTTP/1.1 200 OK
Date: Thu, 05 Jan 2012 21:15:16 GMT
Connection: close
Content-Type: text/xml; charset=utf-8
Content-Type: text/xml; charset=UTF-8
Content-Length: 538
...
Using Fiddler, I removed the extra Content-Type, and the client continued happily. So, I wrote an IClientMessageInspector, with the intention of capturing the response and removing the duplicate. And therein lies my issue. My IClientMessageInspector gets a call to BeforeSendRequest, but not one to AfterReceiveRequest.
Is there some place other than AfterReceiveRequest that I should be handling my task of removing the extra Content-Type? Am I barking up the wrong tree altogether?

Related

Why does GoogleDrive Update API return a 500 error (Unknown Error)?

GoogleDrive update API returns a 500 error.
This error occurs when calling with the title in the request body.
We are sending a request as follows:
PUT https://www.googleapis.com/drive/v2/files/{fileId}
Authorization: Bearer {Authorization}
Content-Type: multipart/related; boundary=25266828
Host: www.googleapis.com
Content-Length: 140
--25266828
Content-Type: application/json; charset=UTF-8
{"title":"renamed_name.jpg"}
--25266828--
The message included the following wording.
[Internal Server Error] [Unknown Error]
We first detected this issue on June 14th.
Previously it worked fine and I haven't changed the source code.
Has there been any change?

ASPNETCore 2 POST method not returning a payload

I upgraded a .net core 1 project to .net core 2. Everything is working great however my POST method won't return any data. There is no payload. I must be missing something simple.
The API does receive what I send it, so no issues there. But there is nothing in the response (using Chrome and IE dev tools), no matter what I try.
Here are the response headers:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Server: Kestrel
Access-Control-Allow-Origin: *
X-SourceFiles: =?UTF-8?B?
For instance this returns no payload:
[HttpPost]
public IActionResult PostOrder([FromBody]OrderDto dto)
{
return new OkObjectResult(dto);
}
Caching policy was setting "Location" to none and "NoStore" to true. Removing this policy solved the issue.

Trouble getting CORS working with Web API 2

I'm having a heck of a time getting Cors working with Web Api. I just created the Web Api with the default template that comes with visual studio 2015. The only changes i made are:
Install-Package Microsoft.aspnet.webapi.cors
In WebApiConfig.cs::Register(HttpConfiguration config):
var cors = new EnableCorsAttribute(
origins: "*",
headers: "*",
methods: "*");
config.EnableCors(cors);
I made the POST method in the values controller async:
public async Task Post(Guid id)
I added a small amount of logic to the post method.
I'm calling the Web Api from another project in my solution:
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("My-GUID",streamProvider.Guid.ToString());
var response = await client.PostAsXmlAsync("http://localhost.fiddler:2010/api/values", myXmlString);
if (response.StatusCode != HttpStatusCode.Created)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}
Request:
POST http://localhost:2010/api/values HTTP/1.1
TRS-GUID: 2ca71b41-9e78-4216-a013-e45c6fd6cb4c
Content-Type: application/xml; charset=utf-8
Host: localhost:2010
Content-Length: 183
Expect: 100-continue
Connection: Keep-Alive
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><?xml version="1.0" encoding="utf-8"?>
<root>
<MbrId>22</MbrId>
</root></string>
Response:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET
Content-Type: application/xml; charset=utf-8
Expires: -1
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?Qzpcc291cmNlXEFzeW5jRmlsZVVwbG9hZERlbW9cc3JjXEFwcFxhcGlcdmFsdWVz?=
X-Powered-By: ASP.NET
Date: Thu, 08 Oct 2015 14:33:08 GMT
Content-Length: 93
<Error><Message>The requested resource does not support http method 'POST'.</Message></Error>
Like i said i've made minimal changed and am running this through IIS express locally. I've been googling around and trying a few things but nothing seems to work. I tried adding the cors options as attributes but it resulted in the same thing. I also seen one post suggesting '*' wasn't in the original spec so i tried by using the methods specfically (POST, PUT, GET) but that didn't work either.
Edit:
Does this have anything to do with the 'preflight' request? I only notice the POST request in fiddler. I don't see it sending an 'options' request across. If this is the issue shouldn't httpclient handle this automatically?
Answer
Thanks goes out to Darrel for the answer. As you can tell the error message coming back was really misleading and definitely sounded like a CORS problem but it wasn't. I never realized CORS was only for the browser. Like Darrell said it was a routing problem. I put a Guid as a POST parameter which caused no route to be matched. To bad the error message coming back couldn't be a little more useful.
There are no cross-origin restrictions for HttpClient. It is purely a web browser constraint. You do not need to implement CORS for HttpClient requests.
Try making the POST request via fiddler and see if that works. I suspect you may just have a routing problem.

Issue in getting Access Token from Windows Azure Media service Using REST API?

I Use below REST call to get the access token from WMS, the problem is, some times it works sometimes it gives error "A server with the specified hostname could not be found", Everything is same but the output is random, why this happens ? I'm using c# console project to make this request.
POST https://wamsprodglobal001acs.accesscontrol.windows.net/v2/OAuth2-13 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Host: wamsprodglobal001acs.accesscontrol.windows.net
Content-Length: 120
Expect: 100-continue
Connection: Keep-Alive
Accept: application/json
Body:grant_type=client_credentials&client_id=ams_account_name&client_secret=URL_encoded_ams_account_key&scope=urn%3aWindowsAzureMediaServices

How do I return a specific SOAP response from an ASP.Net site?

An external development partner has a service that will post a SOAP request to one of our services. The format of their request is fixed (by them).
We are required to respond with a SOAP message of a fixed format (fixed by them again).
I have created a Generic Handler in ASP.Net that successfully receives their request (which we parse manually and process).
However, they want a response that looks like this:
HTTP/1.1 200 OK
Date: Thu, 01 Apr 2010 09:30:25 GMT
Server: Jetty/5.1.4 (Windows XP/5.1 x86 java/1.5.0_15
Content-Type: multipart/related; boundary=soaptestserver; type="text/xml"; start="<theenvelope>"
SOAPAction: ""
Content-Length: 796
Connection: close
--soaptestserver
Content-ID: <theenvelope>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 442
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAPENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"><SOAPENV:
Body><ns1:processResponse xmlns:ns1="urn:TripFlow" SOAPENV:
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><message
href="cid:thecontentmessage"/></ns1:processResponse></SOAP-ENV:Body></SOAPENV:
Envelope>
--soaptestserver
Content-ID: <thecontentmessage>
Content-Transfer-Encoding: 8bit
Content-Type: text/xml; charset=utf-8
Content-Length: 65
<?xml version="1.0" encoding="UTF-8"?><STATUSLVL>00</STATUSLVL>
--soaptestserver--
I have been so sheltered from raw SOAP by using .Net Webservices / WCF for years, that I have no clue about how to go about making a response like this.
What should I do?

Categories

Resources