Error consuming webservice, content type “application/xop+xml” does not match expected type “text/xml”

For anyone suffering from the same problem; I’ve found a solution for consuming the web service as a Service Reference (WCF). The BasicHttpBinding.MessageEncoding property needs setting to “Mtom”. Here’s a snippet of the required config setting: <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding messageEncoding=”Mtom”> </binding> </basicHttpBinding> </bindings> </system.serviceModel> </configuration> Edit: If you are having the same issue … Read more

How to add custom soap headers in wcf?

Check out the WCF Extras on Codeplex – it’s an easy extension library for WCF which offers – among other things – custom SOAP headers. Another option is to use WCF message contracts in your WCF service – this also easily allows you to define and set WCF SOAP headers. [MessageContract] public class BankingTransaction { … Read more

WCF change endpoint address at runtime

So your endpoint address defined in your first example is incomplete. You must also define endpoint identity as shown in client configuration. In code you can try this: EndpointIdentity spn = EndpointIdentity.CreateSpnIdentity(“host/mikev-ws”); var address = new EndpointAddress(“http://id.web/Services/EchoService.svc”, spn); var client = new EchoServiceClient(address); litResponse.Text = client.SendEcho(“Hello World”); client.Close(); Actual working final version by valamas EndpointIdentity … Read more

How to programmatically connect a client to a WCF service?

You’ll have to use the ChannelFactory class. Here’s an example: var myBinding = new BasicHttpBinding(); var myEndpoint = new EndpointAddress(“http://localhost/myservice”); using (var myChannelFactory = new ChannelFactory<IMyService>(myBinding, myEndpoint)) { IMyService client = null; try { client = myChannelFactory.CreateChannel(); client.MyServiceOperation(); ((ICommunicationObject)client).Close(); myChannelFactory.Close(); } catch { (client as ICommunicationObject)?.Abort(); } } Related resources: How to: Use the ChannelFactory

What is the best workaround for the WCF client `using` block issue?

Actually, although I blogged (see Luke’s answer), I think this is better than my IDisposable wrapper. Typical code: Service<IOrderService>.Use(orderService=> { orderService.PlaceOrder(request); }); (edit per comments) Since Use returns void, the easiest way to handle return values is via a captured variable: int newOrderId = 0; // need a value for definite assignment Service<IOrderService>.Use(orderService=> { newOrderId … Read more