Validating call to web service against schema before sending request - c#

I am calling a web service (written in Java) in my web app. I use the WSDL to generate proxy classes using the wsdl.exe command line tool.
Everything is working fine.
However, I have found out that the web service is not doing any data validation at all when they receive a request from my app. Hence, if I happen to send one minute piece of data that isn't exactly what they want, I receive a general fault error in return, with no specifics at all of what the incorrect (if any) piece of data is.
So, before I make the request, I'd like to validate my request against the schema they have provided. Is this possible, and if so, how do I go about this?
Thanks in advance

The proxy built from the wsdl already enforces whatever schema was provided unless, of course, the call takes a string parameter where you are supposed to pass xml. That would be bad design but if that's what you have to do, you can. Just use the XmlDocument object or the XmlReader to validate the XML.

Related

Using NancyFx as proxy

Is there a way to use proxy concept with NancyFx? I mean, I would like to access a service and record the response in my Nancy application (as proxy), either on a JSON file (similiar to wiremock) or in memory (similar to mountebank)
Thanks in advance.
Have you considered WireMock.net as it has a proxy feature and saves the results to json files.
Towards the end of this article is an example of using the proxy feature of wiremock.
You could certainly write a load of code to log the request and response, and use one of the standard web clients to pass the request back to the service, but Nancy has no built in system for this - Nancy is an MVC web framework, not a proxy server.
Perhaps you need something more along the lines of Nginx?

Working with XML and AngularJS - special web method to return JSON how to implement

I was recently assigned the task of creating a login page for my company and they're requiring that I use angularjs for the client side application.
The authenication services are asp.net web services that have already been coded, and return xml because of another service that also uses them.
I notice that AngularJS wants JSON data for it's return value.
I need a way of using AngularJS http methods get and post that will work with data from and to the web server using SOAP. My recent attempts have consisted of trying to get the xml back and then convert it to json on the client side.
Converting on client-side can potentially have problems and so I would prefer to keep all conversations on the server-side.
My solution would be something like have all my web services working as normal. Then have one web service that can take another method in as a parameter and call that method in code and return a json string.
Can anyone give me some input on this. My reason behind not wanting to simply change the web services to return json is because other applications use this service and are expecting xml, also there are more than 1000 web methods in place.
I may have found a solution I am going to work towards. However, if any viable options are still available that would simply add a new method to the list of web methods that would be great. Talking with the developer that wrote all the web services I will need to be using it would be simpler to convert the xml to json on client-side. I am also looking into some angular modules that people have written for get, post for soap services.
Found here
After lots of digging around the best option for me is to use this code Here. I can make the call easily and once I get the xml back just do angular.fromJson(angular.toJson(response)).
If ASP.NET WebAPI is used on the server side it may be sufficient to add an Accept header with the value application/json to the HTML request. It tells the server to return JSON instead of XML.

Execute a SOAP based web services dynamically without generating proxy

In my application, end user can fetch the data from any SOAP based web services and use it in the application. The application provides an option to register the service on fly. The application examine the service, show available operations along with parameter, finally execute the selected operation and use the response, of course everything will be on the fly. There are few steps need to be follow in order to achive that:
Discover the service through WSDL
Examine it and select a method
Build required parameter values
Execute the service
Handle the response
I am able to discover the service on the fly using some WCF classes like DiscoveryClientProtocol, WsdlImporter, ServiceDescription, ServiceContractGenerator, etc. Now, I want to execute them and take the response XML that is available inside SOAP Body.
I am able to execute it by generating the Assembly at runtime using above library and execute a method through reflection. This solution works fine if I have to do everything in single-shot on a box. But it adds complexity when we scale-out. That means, one server generates the proxy, another one use the proxy and consume the services.
Yes, we can keep newly generated assembly somewhere in shared location and use them. But I want to avoid them. We want to keep service definition locally somewhere in DB, execute it without generating assembly and just consume the XML available inside SOAP body.
Appreciate the advice in advance on how to achieve this?
To communicate with WCF services without code generation you use the ChannelFactory< T > where T is the service interface.
Obviously in your case the service interface is not known at compile time so your objective would be to dynamically generate this type, or better yet use a custom ChannelFactory implementation that does not rely on strong typing and lets you call methods in a dynamic or programmatic way.
You can use the WsdlImporter to import the WSDL at runtime and which can give you the ContractDescriptions. From there you might be able to use ContractType as your service interface but I'm not sure. You may need to write your own ChannelFactory...
You can implement ChannelFactory to your abstract generic BaseFactory class which has override CreateDescription method to set Binding and Endpoint for ChannelFactory.ServiceEndpoint. You can pass your configuration interface which has Binding, Endpoint and Credentials to this abstract class. So you can have a dynamic proxy for a wcf service.

SOAPAction and servicestack

don't know if you can help a poor befuddled c# programmer, but here goes. I have a client with a legacy Java Soap app that we need to accept incoming Soap requests from. I have built a solution and tested it and all is well.
When I let the Java app loose on the ASMX file, it fails because I cannot for the life of me get my code to accept the soap action needs to be understood at my end.
The soap action sent is by the Java is:
urn:mycode:uk:gi:dis:supplierenmanager:v02:SupplierManager:AppointManager
Whereas I have used the following against the class that is created when a new web service is added:
<WebService(Namespace:="urn:mycode:uk:gy:dis:suppliermanager:v02:SupplierManager:")>
Then on the method, I have added:
<WebMethod(MessageName:="AppointSupplier")>
This works apart from one little problem. The combination of the above provides the following soap action:
urn:mycode:uk:gi:dis:supplierenmanager:v02:SupplierManager:/AppointManager
As you can see, I am getting an extra forward slash and thus the soap action is rejected.
Does anyone know a work around, or if I am better off using WCF now?
If the answer is USE WCF DUMMY, that is fine and would willing accept that as an answer, but if that IS the case, can someone please point me in the direction of some samples that will explain how to deal with SOAP headers and the dreaded SOAPAction.
Thank you
Can't see a solution to this, but now looking at converting code from ASMX web service to WCF service that consumes soap.
This is because if I create an empty asp.net site and add a wcf service, I can add the following code to the function declaration in the interface code:
<OperationContract
(Action:="urn:mycode:uk:gi:dis:supplierenmanager:v02:SupplierManager:AppointManager")> _
This DOES create the correct SOAPAction.

How could I use C# to send and receive data from Web Service directly?

As a tester, i was asked to test a web service via C#. I've no idea how to use C# directly to send data to Web Service. Could you please give some samples about it? BTW, please do not use the proxy method.
Thanks
Sut
I'd recommend using SOAPUI if you are trying to test SOAP web services directly. Trying to call them using HTTP requests and then parsing the resulting SOAP is going to be quite a chore if you have to use C# and not use the imported proxies.
Note: You'd be much better of if you talk to whoever asked you to do something... instead of asking strangers.
In most cases call to web service is simple HTTP POST or GET. There are plenty of ways to perform it directly - i.e. "How to: Send Data Using the WebRequest Class" ( http://msdn.microsoft.com/en-us/library/debx8sh9.aspx).
And response from web service is generally XML - again plenty of classes to read including XmlDocument and XDocument.

Categories