douzi9744 2018-05-09 13:49
浏览 79
已采纳

如何将数据从网页发送到XML然后发送到SOAP Web服务

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.

  • 写回答

2条回答 默认 最新

  • duanpo7354 2018-05-09 14:53
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 centos7中sudo命令无法使用
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网