1

I have a project file which I have tested using SOAP UI.

enter image description here

Now I wanted to write it's client side so by viewing this solution I have tried to do things work. But I am having a problem.

In the solution, URL and action are mentioned. I have a URL but I am not sure what is my action URL. So I put both of the same.

var _url = "http://111.111.111.1:111/HES/services/DoCommandRequest";
        var _action = "http://111.111.111.1:111/HES/services/DoCommandRequest";

 XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
        HttpWebRequest webRequest = CreateWebRequest(_url, _action);
        InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);

        // begin async call to web request.
        IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);

        // suspend this thread until call is complete. You might want to
        // do something usefull here like update your UI.
        asyncResult.AsyncWaitHandle.WaitOne();

        // get the response from the completed web request.
        string soapResult;
        using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
        {
            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
            {
                soapResult = rd.ReadToEnd();
            }
            Console.Write(soapResult);
        }

After running my code I am getting an exception at using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) which says

System.Net.WebException {"The remote server returned an error: (500) Internal Server Error."}

I believe that there is some problem with my action, but I am not sure.

Any help would be highly appreciated.

Moeez
  • 494
  • 9
  • 55
  • 147
  • 1
    I see you're building XML with string concatenation: this is a bad idea. XML has encoding rules that will catch you out. .NET has multiple options for building XML that will do the hard work for you. – Richard Mar 30 '19 at 11:04
  • Where in the code is the reply XML you're trying to process? (And what is the `DataTable` for? It is loaded from an array and then iterated over... which can be done with an array directly.) – Richard Mar 30 '19 at 11:06
  • What is a "string file"? What do files have to do with a web service? Are you asking how to make an HTTP request to the service? If so please specify that more clearly in the question. – Tom W Mar 30 '19 at 13:10
  • @TomW I have updated my question and added some more details you can see it – Moeez Mar 31 '19 at 05:06
  • @Richard Yes I am unable to get the reply. I have also update my question and added some more details. Can you please see it ? – Moeez Mar 31 '19 at 05:07
  • This is too broad. Try to pinpoint the place in the code where it behaves different than what you expect. Create a [mcve] containing input data of that point in code and expected output. Most of the time, the process of creating an [mcve] will be enough for a person to understand where the problem is and fix it. – Zohar Peled Mar 31 '19 at 05:53
  • @ZoharPeled I have updated again with minimal and completer information – Moeez Mar 31 '19 at 06:38
  • First there was too much information, now there's too little... – Zohar Peled Mar 31 '19 at 06:39
  • Possible duplicate of [How to make HTTP POST web request](https://stackoverflow.com/questions/4015324/how-to-make-http-post-web-request) – Tom W Mar 31 '19 at 07:22
  • You don't modify a SOAP file to call a WCF (or similar) service by directly using that SOAP. Rather you use a service reference to allow tooling to build a client library (eg. Visual Studio this is add service reference). That gives you methods to call that will make the RPC for you. – Richard Mar 31 '19 at 07:41
  • @Richard I have updated the question can you please see it? – Moeez Mar 31 '19 at 08:02
  • @ZoharPeled updated my question again – Moeez Mar 31 '19 at 08:02
  • It looks like you are trying to implement the client side manually (ie. not using tooling to generate a client side proxy). Goo luck, you'll need it. The WS-* (aks "WS-Death Star") standards are very complex. – Richard Mar 31 '19 at 08:06
  • @Richard So you want me to use tool for it? – Moeez Mar 31 '19 at 08:11
  • I would strongly recommend not trying to hand write a SOAP service client, use tooling to do that. (That the server is return 500 is very unhelpful: you can't tell if you're doing it wrong or if the server is itself wrong.) – Richard Mar 31 '19 at 09:20

1 Answers1

0

SOAPAction is required in SOAP 1.1 but can be empty (""). See the comment here

First of all you should try to create new SOAP project using your link to wsdl file. After that try to do request from SOAP UI. Try to run "doCommand" action. Look at the result. Than you can compare it with request from your app. You can also use Fiddler to intersept your requests and compare them to find a difference.

Serhii
  • 723
  • 1
  • 4
  • 12