I have tried using pact-JVM for an endpoint which returns a soap XML response.
For XML response it looks like it does string comparison, Can we do XML validation against XSD or can we write matchers for XML?
Need suggestion as well, is it a good idea to use pact-JVM to write a contract test case for an endpoint that returns soap XML?
Please share a sample example for it.
There is a PactXMLBuilder that you can use that is namespace aware and you can match on.
Here is an example https://github.com/DiUS/pact-jvm/blob/7ff6491a0923e4709a8f78ab5451a99989559712/consumer/junit/src/test/java/au/com/dius/pact/consumer/junit/xml/TodoXmlTest.java
Related
I don't have something in particular that I need to implement, I am just trying to understand some concepts.
As far as I know, .NET web method (for example), that is inside a web service, is using the SOAP protocol. that means that the data received to the server needs to be in XML format, and the data that is returned from the web method should also be in XML format.
I know I can write something like this:
[WebMethod]
public static Object someMethod(Object josn)
{
Console.Write(json("someProperty"));
return new {name = "John"}
}
I know that data sent back to the client is in JSON format...
but if we are using the SOAP protocol, shouldn't it return XML?
I want to understand what is happening behind the scene or what am I missing, does the request was sent in xml format and the .NET framework knows how to extract the parameters that were sent, if so- how can I retrieve the full xml that represents the request made?
What you are referring to is called the SOAP envelope. Take a look here:
Sample SOAP Envelope
One of the easiest ways to see the SOAP envelope that is being used in a request or response is to use Fiddler or Postman.
EDIT
Here's an example of WCF SOAP envelope with JSON (not sure if you are using WCF or the old .NET Web Service with ASMX files):
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing">
<s:Header></s:Header>
<s:Body>[{"DateOfBirth":"\/Date(286801200000+1300)\/","FirstName":"Foo","Id":1,"LastName":"Bar"},{"DateOfBirth":"\/Date(333720000000+1200)\/","FirstName":"Foo","Id":1,"LastName":"Bar"}]</s:Body>
</s:Envelope>
I have a requirement.
I have a xml file and after transformation I need to send the payload to a soap service.
I have been using http-request for rest. But now for soap service which component should I use to send data.
I hope http-outbound is deprecated now.
Any help with example is appreciated
You could use http Request as well for sending soap request, you could use the XML to post to the Soap web service.
You could either use Web Service Consumer or Http-request + CXF.
https://docs.mulesoft.com/mule-user-guide/v/3.7/consuming-web-services-with-cxf
https://docs.mulesoft.com/mule-user-guide/v/3.6/web-service-consumer
I have used WSConsumer Component. I have read all the details from the property file And its working as intended
I am creating a WCF service and I am planning to set the message format as JSON. But when I use BasicHttpBinding, I get the response and request in XML format. I am not sure does that mean this WebMessageFormat.Json can be used only in WEBHttpBinding (REST)? I have an understanding that SOAP uses only XML but this MessageFormat attribute arise a question in me whether JSON format can be used across all binding.
I am confused on one thing. As I have read web services use SOAP protocol for communication and it is an XML based protocol; I was expecting the classical HelloWorld method on an asp.net web service to return an xml based data.
But when I checked with Fiddler i see that the Response Textview has a JSON string instead of an XML structure like:
{"d":"Hello World"}
Does this mean that asp.net web-service implementation returns 'string' types embedded as a value of a property called 'd' ?
Web services don't have to use SOAP as the protocol. The WCF lets you use all sorts of protocols for your web services. SOAP and JSON are just 2 of the options.
ASMX services return JSON if you request them via POST, with a content-type containing application/json. More info here: http://encosia.com/2010/03/03/asmx-and-json-common-mistakes-and-misconceptions/
Their return value isn't limited to just strings either. If you return a collection type, you'll get a JSON array. If you return a server-side class, that will be serialized into the correct JSON key/value pairs to represent that object.
The .d is sort of an orthogonal issue. It's a security feature to thwart a particular attack against JavaScript's Array constructor. More here: http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/
Ok. I have found my answer, here:
"ASP.NET AJAX sends JSON messages to Web Services as opposed to the standard Simple Object Access Protocol (SOAP) calls typically associated with Web Services. This results in smaller request and response messages overall. It also allows for more efficient client-side processing of data since the ASP.NET AJAX JavaScript library is optimized to work with JSON objects. "
More details in :
http://www.asp.net/ajax/tutorials/understanding-asp-net-ajax-web-services
As you can see here JSON responses are supported by recent releases of the .NET Framework.
I have been given a wsdl and have used wsdl.exe to create my proxy classes.
I am able to call the function to initiate the request with some valid parameters and this returns my response object which is always EMPTY.
When i inspect the soap message response using fiddler the soap does have valid data that should be deserialzed to the proxy classes.
Can i manually intercept the derserializing call of the proxy classes generated by wsdl and check that .net is correctly derializing the soap response?
Thank you
The empty object is most likely the result of a mismatch between the soap message and your proxy class. This can for example be caused by a difference in namespaces (newer version).