0

Till now, we had a backend SOAP web service for our application which used xml input to hit the service. But now we are trying to build the front end which takes a few inputs from the user and updates only the xml atomic values accordingly, as we have the xml structure already. After the xml is updated from user values the service should hit with that xml as the input.

So the flow will be like: user input(html) --> update xml --> pass this xml as input to SOAP web service --- service response.

I have no idea what technologies can be used for this and how can it be done, for updating the xml I started with php and xpath, I don't know if I am right. Can anyone please help me with this and suggest the solution?

Also, my xml has soap headers, so I am having trouble using this xml with xpath, as xpath uses pure xml. Any solution on this too?

java, springs is used for backend development.

Harsha
  • 87
  • 1
  • 14

2 Answers2

0

If you have java platform then this solution will be helpful to you. For this purpose I've created new web application project and used Web Service Wrom WSDL wizard in Web Services category. The implementation was easy:

@WebService(serviceName = "AddNumbersService", portName = "AddNumbersPort", endpointInterface = "org.example.duke.AddNumbersPortType",
            targetNamespace = "http://duke.example.org", wsdlLocation = "WEB-INF/wsdl/AddNumbersImpl/AddNumbers.wsdl")
public class AddNumbersImpl implements AddNumbersPortType {

    public int addNumbers(int arg0, int arg1) throws AddNumbersFault {
        int result = arg0+arg1;
        if (result < 0) {
            org.example.duke.xsd.AddNumbersFault fault = new org.example.duke.xsd.AddNumbersFault();
            fault.setMessage("the result is negative");
            fault.setFaultInfo("negative result: "+result);
            throw new AddNumbersFault("error", fault);
        } else {
            return result;
        }
    }

    public void oneWayInt(int arg0) {
        System.out.println("JAX-WS: oneWayInt request "+arg0);
    }

}
crenshaw-dev
  • 7,504
  • 3
  • 45
  • 81
Rajan Desai
  • 79
  • 1
  • 11
  • May be I will have to research more on wsdl wizard and try to implement the code, because I have limited knowledge on it. Thanks a lot for your answer. – Harsha May 10 '18 at 03:30
0

It's difficult to provide a precise answer without knowing the exact environment you're working with (target web service, preferred programming language, etc.). But I'll attempt a general answer.

Consuming the Web Service

SOAP webservices often (always?) provide a machine-readable description which can be "consumed" by some tool, generating code in your favorite language to interact with the API.

For example, Salesforce offers a description of their SOAP API, customized for a given account, in the form of a WSDL (Web Service Description Language) file. It is XML, like SOAP requests/responses. For my applications, I have used Visual Studio to create a reference in my project to Salesforce's API using the WSDL file. The rest is done with simple object initialization and methods. For example:

using ServiceName;  // Namespace generated by Visual Studio using the WSDL.

var client = new ServiceClient("username", "password");

client.Create(new ServiceThing("information", "about the new thing"));

This example in C#-like syntax would call the SOAP API to create some object with the given information. The details of the network request are completely hidden.

To learn how to consumer your target API's services, search for something like "consume WSDL in [language of your choice]". Even better, see if the target web service has documentation describing how to consume it.

Sending Data from Web Page

There are any number of tools to retrieve information from an HTTP POST request and act upon it. I'm most familiar with ASP.NET. You seem familiar with PHP.

To keep things simple, you'll want to try to consume the target web service using the same language as your web service that receives input from the user. I'll provide an ASP.NET-like example which hopefully you can translate to your preferred tools:

protected void Page_Load(object sender, EventArgs e) 
{
    if (Page.IsPostback)
    {
        // a and b are names of input fields in our page.
        string a = Request["a"];
        string b = Request["b"];

       // Let's assume we've initialized the web service client as a property.
       Client.Create(new ServiceThing(a, b));
    }
}

There you go. No manual XML editing necessary. The SOAP XML is automatically generated based on your ServiceThing object and send to your target web service.

Again, this is a general answer to a general question. If you update your question with more specifics, I'll try to edit this answer with more targeted details.

crenshaw-dev
  • 7,504
  • 3
  • 45
  • 81
  • Hi mac, Thank you for your answer, It was helpful, but still as you said I will update my question. – Harsha May 10 '18 at 03:22
  • I am using html,php in front end and xpath to map values to xml, after that still I am in decision making phase for what can be done. – Harsha May 10 '18 at 03:36
  • @Harsha is it necessary to export HTML response values to XML and then to a SOAP request? In other words, is there some reason you have XML files besides storing values to send to the SOAP service? My answer assumes we can cut out that middle step. But you might have to do some XML processing if there are other requirements depending on the XML files. – crenshaw-dev May 10 '18 at 13:29
  • Yes because the xml has a predefined structure which the service will take as input.And it will have few input values too , which wont be given by the enduser. – Harsha May 11 '18 at 02:33
  • If the XML structure accepted by the service is SOAP, you should be able to use a WSDL as described above to access the XML (SOAP) structure programmatically. – crenshaw-dev May 11 '18 at 13:03