Consuming wsdl soap service with servicestack - asp.net-mvc-4

I have been trying to consume wsdl soap service with asp.net C# mvc5 application. The original service is written in php which should ideally not matter but I have not been able to make this work. I have just learnt that servicestack is an alternative that works well with mvc architecture. I am looking for pointers on how to consume wsdl soap service with servicestack any help on this will be appreciated. I am happy to buy books that will guide me on how to any of these two methods will work with my mvc application

ServiceStack allows your .NET Services to be exposed via SOAP endpoints by automatically generating WSDL's and XSD's for SOAP Compatible Services which can be consumed with either the generated client proxy created with VS .NET's Add Service Reference or with ServiceStack's .NET Soap11ServiceClient and Soap12ServiceClient.
But ServiceStack doesn't provide a general purpose SOAP client for consuming any 3rd party SOAP Services. SOAP's an unnecessarily complex and brittle format where your best option is to ask the developers of the PHP SOAP Service if they can recommend any .NET SOAP clients since it's unlikely any independent SOAP client implementations will be interoperable without issues unless they've been tested and verified as compatible.
Failing that the most reliable option is to treat the SOAP XML as a string where you construct a raw SOAP Request and POST it to the remote endpoint, e.g SOAP 1.1 Request:
var soapRequest = #"<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>"
+ requestXml
+ "</soap:Body></soap:Envelope>";
Example POST'ing XML using HTTP Utils:
var soapResponseXml = soapEndpointUrl.PostXmlToUrl(soapRequest,
httpReq => httpReq.Headers["SOAPAction"] = requestName);
Then parse the SOAP Response with WCF's Message.CreateMessage(), if even WCF generic Message doesn't support the SOAP Response you can try to parse it dynamically as XML using something like XLINQ's XDocument.

Related

is it possibe to consume external asmx ,wcf ,soap services from .net core?

I have a requirement to consume all external services like asmx, wcf ,soap based services in .net core to make it as restful and then consume in the response in angular.
I don't see any examples to configure in middleware pipeline in .net core. else we need to use httpclient or web-client in c# classes to consume that. is it better way or .net core recommended way
share your thoughts.helpful if have any examples.
There are several ways to do this. Essentially, you are making a .Net Core wrapper for the Soap service. There are many samples on StackOverflow for this as well.
You can:
1.consume a .wsdl file
2.point to a svc or asmx
3.use Postman by pointing to the endpoint and then generate the code.
The first two approaches will automatically generate a Reference class for you.
With the 2nd approach, a SoapClientInterface and SoapClient will be generated. You can use the interface for dependency injection.
If you just want to instantiate the Soap client, you can then call methods in your Soap client. The calls will be async.
If you are using DataSets or DataTables as return from the Soap client, they will instead be returned as ArrayOfXElement.

SOAP with Attachment Client in .NET

I'm attempting to build a C# SOAP client which uses SOAP with Attachment. From what I've read, my understanding is that WCF does not have an out-of-the-box solution for this.
Does this mean that the proxy generated from the server's WSDL via svcutil.exe won't be of use to me?

Consuming WCF service (without metadata) on a non-.net platform

I have created a WCF service and hosted it through self hosting. This service doesn't have any metada published.
First Question
Can I consume it through Visual Studio, Add Service Reference? Hopefully not.
Can I consume it by creating manual proxy, i.e. ChannelFactory<ServiceContract>....?Hopefully yes.
Now in the second scenario, the client must be .Net, right?
So it implies that, to consume a wcf service on a non-.net platform, we have to expose its metadata?
Can't a WCF service without metadata, consume by Ajax client, or say Java client??
There are 3 options to consume a WCF Service:
If the service exposes a WSDL use "add service reference" from VS (or an equivalent from another platform). Note that if you do not want to expose the WSDL you could expose it just temporarly, save the WSDL in a file, and then send it to user in any platform to generate proxy from it. You can turn off the WSDL immediately after you save it. Also note that even if the WSDL is not exposed still you need to protect the web service from unauthorized access.
If this is a .Net client it can compile with the same Service Contract assembly and use ChannelFactory etc.
Any platform can send raw soap message (e.g. XML) to the service. Of course they need to know what is the right format. A WSDL can help but even without it if they have a working sample they can imitate it.
WCF provides REST (Representational State Transfer) support to consume it by non .NET client like JavaScript (AJAX), java, Objective C, web browser, etc...
Basically WCF REST is exposes methods and transferring data over the HTTP protocol and it supports all HTTP operations (GET, POST, PUT, and DELETE). This feature is making it platform independent as well as it doesn’t require metadata exposed.
Please refere below links to get more about WCF REST:
An Introduction To RESTful Services With WCF
WCF REST Programming Model Overview
WCF Rest vs. WCF SOAP
Create RESTful WCF Service API: Step By Step Guide

Microsoft WCF - SOAP messaging protocol

is that correct that the default Web Service created using WCF will have WSDL but the message transmission required should not have SOAP tags like
<soap:envelope>, <soap:header>, <soap:body> ?
Are they still using SOAP 1.1 in this case then?
And then, how can I create another web service using JAX-WS that is following this standard?
Thanks a bunch,
Robert
It's not clear to me what you're asking but if you're trying to invoke java based services (Apache, Metro, etc...) with a WCF client, take a look at the WCF Express Interop bindings.

Is there any advantages of using WCF to Consume REST API?

Are there any real advantages of using WCF client for consuming REST api. I have api which returns result in SOAP and REST format. Are there any specific advantages of using WCF for consuming this REST API ?
Current WCF version doesn't have any real client for REST services. You should check HttpClient from Web-API as an option (HttpClient will be also part of upcoming .NET 4.5).
Or you could user the existing WebClient class that is already released in mainstream .Net
http://msdn.microsoft.com/en-us/library/tt0f69eh.aspx