Using a web service using POST instead of the usual WSDL route

Here's how I managed to currently use a specific Microsoft web service. Please note that it is located on the HTTPS server and requires that the username, password and .cer file are .cer in the root certification authority of the operating system.

 WSHttpBinding binding = new WSHttpBinding(); binding.Security.Mode = SecurityMode.TransportWithMessageCredential; binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName; binding.Security.Message.NegotiateServiceCredential = true; binding.Security.Message.AlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default; binding.Security.Message.EstablishSecurityContext = true; EndpointAddress endpoint = new EndpointAddress("https://address.of.service"); //"GreatClient" was created for me automatically by running //"svcutil.exe https://address.of.service?wsdl" GreatClient client = new GreatClient(binding, endpoint); //Username and password for the authentication. Notice that I have also installed //the required .cer certificate into the system "root certificate authorities". client.ClientCredentials.UserName.UserName = "username"; client.ClientCredentials.UserName.Password = "password"; //Now I can start using the client as I wish. 

My question is this:. How can I get all the necessary information so that I can use the web service with direct POST to https: //address.of.service , and how can I do POST with C #? I just want to use POST, where I can supply raw XML data using POST directly to https: //address.of.service and return the result as raw XML data. The question is, what kind of raw XML data is it and how exactly should I send it using POST?

( The purpose of this question: The reason I'm asking is because I want to use this service using something other than C # and .NET (like Ruby or Cocoa on Mac OS X) I don’t have opportunities to learn how to do this because I don’t have easy to use “svcutil.exe" on other platforms to create the necessary code for me. That's why I decided that just being able to use the service using a regular POST will allow me to use this more easily service on other platforms.)

+6
source share
5 answers

What you are trying to do seems painful to do now and it hurts to keep moving forward if something changes on the server. He really invents the wheel.

If you have not thought about this, I would:

(a) Examine whether you can use the metadata that you have for this service and use the proxy generator for the target destination form. There are not many platforms that do not have at least some tools that can help you in part, if not all. Perhaps repeat the question aimed at the Ruby user asking what structures exist for using the HTTPS service given its WSDL?

(b) Otherwise, if your script allows this, I would consider using a proxy server written in C #, which acts as a facade for a service that translates it into something simpler (for example, you can use something- something like ASP.NET MVC WebAPI, which is flexible and can easily serve answers that are compliant with standards by which you can maintain full control).

I suspect that one of them may be simpler and more valuable than the one you are currently on.

+1
source

I had to go through something similar when porting .NET WCF code to other platforms. The easiest approach I've found is to enable message logging in the WCF client . This can be configured to save both the envelope and the body, and once everything works on the .NET side of the house, you can use the message log to have a “well-known” XML request / response to the port on other platforms.

I found this approach more elegant, since I did not need to add additional behavior for log messages, and it can be easily turned on / off / configured in the config. The trace viewer utility that ships with Visual Studio is also useful for viewing log files.

+1
source

I think that when you say that the service should be consumed from other platforms that do not have the proxy class generation logic, you can use REST services. This allows you to create input as a simple string concatenation instead of complex XML. Although its applicability depends on the situation.

Check out this discussion: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/6907d765-7d4c-48e8-9e29-3ac5b4b9c405/

For a certificate, see http://msdn.microsoft.com/en-us/library/ms733791.aspx on how to configure it.

I know that this is not a very accurate answer, but you will be the best person to evaluate above the procedure, therefore published. Hope this helps.

+1
source

What will I do:

1- Create a small C # application that can be hosted on this web service (using svcutil). And change it to show send / receive XML. There are several ways to view xml: logging, wireshark, etc. To add it directly to a small application, there is another question here that gives a good answer.

2- Once you know what you need to send, you can do it in C # as follows:

 // implement GetXmlString() to return the XML to post string xml = GetXmlString(); // create the url string url = new UriBuilder("http","address.of.service",80).ToString(); // create a client object using(System.Net.WebClient client = new System.Net.WebClient()) { // performs an HTTP POST client.UploadString(url, xml); } 
+1
source

I am not a .NET programmer, but I had to interact with several .NET services and have many SOAP / WSDL features. It looks like you grabbed the XML for your service. Another problem you will encounter is authentication. OOTB, .NET Web Services uses NTLM for authentication. Support for the open source language for NTLMv2 can be removed and skipped (although a quick Google search dragged on several features for rubies), and using NTLM authentication over HTTP may be something you need to put together. To answer the question above: where are authorized loans? If the service uses NTLM over wire, authentication takes place at some level below HTTP. If the service uses NTLM for HTTP authentication, your NTLM accounts are in the HTTP authorization header. You should be able to tell with wirehark where they are. You will probably also need the SOAPAction header; it can also be sniffed by wires. For a C # client, I am sure there are documents explaining how to add headers to your request.

+1
source

Source: https://habr.com/ru/post/912151/


All Articles