I am trying to send a request using a wcf client to a ColdFusion 9 service using json. However, the content-type of the request is for xml.
Here is the service contract. As you can see we specificy using RequestFormat of json.
[ServiceContract(Name = "ServiceAgreementRequestService", Namespace = NetworkNamespaces.ServiceNamespace)]
public interface IServiceAgreementRequestService
{
[OperationContract]
[FaultContract(typeof(RequestFault))]
[WebInvoke(UriTemplate = "?method=CreateUser", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
CreateUserResponse CreateUser(CreateUserRequest request);
}
I have also tried to set the Request.ContentType on the OutGoing request and this also did not work.
using (var context = this.GetServiceClient(clientId))
{
WebOperationContext.Current.OutgoingRequest.ContentType = "application/json; charset=UTF-8";
var request = new CreateUserRequest(user.Id, user.Person.FirstName, user.Person.LastName);
var response = context.Channel.CreateUser(request);
}
Here is the request that gets sent
POST http://somesite.domain.com/WebServices/ProviderService.cfc/?method=CreateUser HTTP/1.1
Content-Type: application/xml; charset=utf-8
VsDebuggerCausalityData: uIDPo7eh9U9jsBVLqVgGtqTK+eMBAAAAb++0xkOSQEmcAKZLgQEsp2/muY2ca6NJiul6pkAaWZwACQAA
Host: somehost.domain.com
Content-Length: 58
Expect: 100-continue
Accept-Encoding: gzip, deflate
{"UserId":4,"FirstName":"FirstName","LastName":"LastName"}
How do I get this to use the correct content-type?
EDIT:
Under the hood, the GetServiceClient(clientId) call uses system.servicemodel.clientbase and ChannelFactory to create the communication channel. The endpoint that we call out to changes by client so we have some code on top of those to dynamically change out the endpoint.
Some more info. We have two applications : One is a .net MVC 4 web application to host the client app and one is a .net WCF Server application to host the backend services. I can call out to the ColdFusion app successfully from the web application, but not the wcf Server application. These both use the same code base to make the outgoing call.
As far as I can tell the config is the same for both.
<system.serviceModel>
<endpointBehaviors>
<behavior name="WcfRestBehavior">
<webHttp />
</behavior>
<client>
<endpoint name="ServiceAgreementRequestService" address="http://PLACEHOLDER/" binding="webHttpBinding" behaviorConfiguration="WcfRestBehavior" contract="IServiceAgreementRequestService"/>