soap 相关问题

简单对象访问协议(SOAP)是用于在Web服务的实现中交换结构化信息的协议规范。

SOAP 的 PHP 数组/对象结构 (WSDL/wsse)

我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders) 假设实际输出应该如下所示: 我必须了解如何使用 PHP 生成此示例 WSDL 的结构。 (SoapClient、SoapHeaders) 假设实际输出应该如下所示: <soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3"> <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4"> <wsse:Username>name</wsse:Username> <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password> <wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:ProcessMsg> <req:Payload> <req:Request> <req:Sub>DATA_1</req:Sub> <req:EID>DATA_2</req:EID> <req:IID>DATA_3</req:IID> <req:Customer FirstName="xxx" LastName="xxx"></req:Customer> <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead> </req:Request> </req:Payload> </asi:ProcessMsg> </soapenv:Body> </soapenv:Envelope> 我尝试了三种不同的结构,但都不起作用 new \stdClass(); new \ArrayObject(); 数组() “new SoapHeader();”的结构 $Security = new \ArrayObject(); $Security['UsernameToken'] = new \ArrayObject(); $Security['UsernameToken']['Username'] = "name"; $Security['UsernameToken']['Password'] = "good_password"; // OR $Security = new \stdClass(); $Security->UsernameToken = new \stdClass(); $Security->UsernameToken->Username = "name"; $Security->UsernameToken->Password = "good_password"; $header = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/secext','Security',$Security,false); $soapClient->__setSoapHeaders($header); “$soap_client->ServerMethod("Payload", $soap_request);”的结构: $soap_request = new \ArrayObject(); $soap_request['Payload'] = new \ArrayObject(); $soap_request['Payload']['Request'] = new \ArrayObject(); $soap_request['Payload']['Request']['Sub'] = "xxx"; $soap_request['Payload']['Request']['EID'] = "xxx"; $soap_request['Payload']['Request']['IID'] = "xxx"; $soap_request['Payload']['Request']['Customer'] = new \ArrayObject(); $soap_request['Payload']['Request']['Customer']['_'] = ''; $soap_request['Payload']['Request']['Lead'] = new \ArrayObject(); $soap_request['Payload']['Request']['Lead']['_'] = ''; foreach ($data['x'] as $key => $value) { $soap_request['Payload']['Request']['Customer'][$key] = $value; } foreach ($data['xx'] as $key => $value) { $soap_request['Payload']['Request']['Lead'][$key] = $value; } // OR $soap_request = new \stdClass(); $soap_request->Request = new \stdClass(); $soap_request->Request->Sub = "xxx"; $soap_request->Request->EID = "xxx"; $soap_request->Request->IID = "xxx"; $soap_request->Request->Customer = new \ArrayObject(); $soap_request->Request->Customer['_'] = ''; $soap_request->Request->Lead = new \ArrayObject(); $soap_request->Request->Lead['_'] = ''; foreach ($data['customer'] as $key => $value) { $soap_request->Request->Customer[$key] = $value; } foreach ($data['lead'] as $key => $value) { $soap_request->Request->Lead[$key] = $value; } 我尝试调试结构的事情: echo "FNs:\n" . $soapClient->__getFunctions() . "\n"; echo "REQUEST:\n" . $soapClient->__getLastRequest() . "\n"; echo "REQUEST (htmlent):\n" . htmlentities($soapClient->__getLastRequest()) . "\n"; 我遇到的错误消息: 输入格式不正确或不包含预期数据 调用 PropertySet.GetChild() 失败。 (该属性集没有任何子级。(SBL-EXL-00144)) 实际发送执行: $soap_response = $soapClient->ServerMethod($soap_request); 嗯,我现在真的陷入困境,不知道是否要搜索错误/错误,因为我没有任何“好的”详细错误需要调试。 这是我第一次必须使用 SOAP(将数据发送到服务),也许我完全错了?非常感谢您的帮助。 核心问题: php 内部的结构与所有命名空间是什么样子的, 属性,嵌套元素? 问题在于内置 PHP 函数 SoapHeader 需要提供广泛兼容的 SoapHeader。您可以通过扩展 PHP SoapHeader 类来查看实现。 我使用了 stdClass 对象作为有效负载。并通过将所有属性传递到最深的对象层来获取实际的数据字段。我希望通过我的问题的答案为某人节省一些研究。 安全肥皂头: namespace AppName\TheBundle\Services; use SoapHeader; use SoapVar; class AuthSoapHeaderHelper extends SoapHeader { private $wss_ns = 'http://schemas.xmlsoap.org/.../secext'; private $username = "username"; private $password = "good_password"; function __construct() { $auth = new \stdClass(); $auth->Username = new SoapVar($this->username, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $auth->Password = new SoapVar($this->password, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns); $username_token = new \stdClass(); $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns); $security_sv = new SoapVar( new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns); parent::__construct($this->wss_ns, 'Security', $security_sv, true); } } SOAP 有效负载: $soap_request = new \stdClass(); $soap_request->Payload = new \stdClass(); $soap_request->Payload->Request = new \stdClass(); $soap_request->Payload->Request->Sub = "DATA_1"; $soap_request->Payload->Request->EID = "DATA_2"; $soap_request->Payload->Request->IID = "DATA_3"; $soap_request->Payload->Request->Customer = new \stdClass(); $soap_request->Payload->Request->Lead = new \stdClass(); foreach ($data['x'] as $key => $value) { $soap_request->Payload->Request->Customer->{$key} = $value; } foreach ($data['xx'] as $key => $value) { $soap_request->Payload->Request->Lead->{$key} = $value; } 这导致了以下 wsdl/xml 结构: <soapenv:Envelope xmlns="http://schemas.xmlsoap.org/1"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/3"> <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/4"> <wsse:Username>username</wsse:Username> <wsse:Password Type="wsse:PasswordText">good_password</wsse:Password> <wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:ProcessMsg> <req:Payload> <req:Request> <req:Sub>DATA_1</req:Sub> <req:EID>DATA_2</req:EID> <req:IID>DATA_3</req:IID> <req:Customer FirstName="xxx" LastName="xxx"></req:Customer> <req:Lead LeadMaster="xxx" IntendedRepPer="xxx"></req:Lead> </req:Request> </req:Payload> </asi:ProcessMsg> </soapenv:Body> </soapenv:Envelope>

回答 1 投票 0

通过 SOAP 调用从 ORN 获取外展活动数据

我通过 SOAP API 使用 Oracle RightNow。 使用 QueryCSV 选项,我可以获得很多信息(例如:关于事件 SELECT * FROM Incident WHERE ...),但我不知道如何获取有关

回答 1 投票 0

我能够使用soap UI和post man将请求发送到spring boot肥皂端点,但是在尝试从SAP获取错误500时

我能够使用soap UI和post man将请求发送到spring boot肥皂端点,但是在从SAP尝试时,我收到500错误并在java代码中收到以下错误 SAAJ0511:无法

回答 1 投票 0

Spring boot - 服务器无法识别 HTTP 标头 SOAPAction 的值

我想使用jaxb使用肥皂服务。 jaxb 生成的请求是 ...

回答 3 投票 0

Nodejs SOAP 模块 - 超时选项

如何设置soap.createClient和/或client.myFunction的超时?文档中没有提及。如果不可能,有解决办法吗?

回答 3 投票 0

如何修复使用默认绑定在 .NET Core 中使用 Web 服务时出现的“TransportBindingElement”错误?

我正在尝试在我的 dotnet core7 项目中使用 Web 服务。 我无权访问该服务本身。 当我尝试调用服务方法时,它返回该错误:

回答 1 投票 0

WSDL JAVA w3.org 文件过早结束

[错误] 文件过早结束。 第 1 行 http://www.w3.org/2005/05/xmlmime [错误] org.xml.sax.SAXParseException;系统ID:http://www.w3.org/2005/05/xmlmime;行号:1;列数:1;提前...

回答 1 投票 0

如何在 Vue.js 中调用 SOAP Web 服务器方法?

我用Delphi开发了一个小型独立网络服务器。程序如下: 函数 sum(a,b:string):string;stdcall; 开始 结果:=a+b; 结尾; 我如何在 Vue JS 中调用它? Web 服务 URL 我...

回答 1 投票 0

在 wso2 api 管理器网关 https://IPaddr:9443/services 中禁用肥皂

我想禁用在 wso2 api manager 3.2.0 网关中显示肥皂服务。 由于安全风险(肥皂操作欺骗),我不希望出现此页面。如何限制对此页面的访问?

回答 1 投票 0

独立的网络服务器来服务 HTTP GET 请求

我正在开发一个基于使用gsoap v2.8的网络服务器(FCGI)。 该网络服务器应响应传入的 HTTP GET 请求,但它不工作。 我知道 gsoap 提供了 HTTP 回调

回答 1 投票 0

__soapCall - 如何拨打正确的电话?

我是 PHP WS 调用的新手。谁能告诉我如何从这个 WS 读取数据。 这是我的代码 $wsdl =“https://test.saljfinans.handelsbanken.se/xml/netxservice.wsdl”; $用户名 = '用户'; $

回答 1 投票 0

如何从 Oracle DB 11.2 调用负载超过 32000 个字符的 SOAP WS?

各位同事,大家好。我需要从 Oracle DB 调用 SOAP Web 服务,其中有效负载由 base64 编码的文件组成。问题是我的有效负载大小有限制 - 32 000 个字符(varchar ty...

回答 2 投票 0

发送字符串而不是 JAXBElement<String>

我正在使用 Java 项目中的 .NET Web 服务。我正在使用 Netbeans 8.2 并导入了 Web 服务。当我创建复杂对象时,问题就出现了,Netbeans 或 Java 转换了 e...

回答 1 投票 0

android.os.NetworkOnMainThreadException 即使使用 Aysnc 任务

我正在尝试使用 Android studio 调用 SOAP 服务,但出现以下异常 android.os.NetworkOnMainThreadException 我知道应该是在主线程上运行网络调用时......

回答 1 投票 0

需要Java中的解析器从XML(SOAP)到JSON

我正在寻找 Java 中的解析器或 SOAP 客户端,以将 XML(WSDL)从 Magento SOAP v1 API 转换为 JSON 对象。 Magento SOAP v1 API 返回一个 XML,如下所示: 我正在寻找 Java 中的解析器或 SOAP 客户端,以将 XML(WSDL) 从 Magento SOAP v1 API 转换为 JSON 对象。 Magento SOAP v1 API 返回一个 XML,如下所示: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <ns1:callResponse> <callReturn xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">store_id</key> <value xsi:type="xsd:string">1</value> </item> <item> <key xsi:type="xsd:string">created_at</key> <value xsi:type="xsd:string">2013-03-05 05:56:35</value> </item> <item> <key xsi:type="xsd:string">updated_at</key> <value xsi:type="xsd:string">2017-11-09 15:37:05</value> </item> <item> <key xsi:type="xsd:string">shipping_address</key> <value xsi:type="ns2:Map"> <item> <key xsi:type="xsd:string">address_id</key> <value xsi:type="xsd:string">1</value> </item> <item> <key xsi:type="xsd:string">created_at</key> <value xsi:type="xsd:string">2013-01-31 11:37:38</value> </item> <item> <key xsi:type="xsd:string">updated_at</key> <value xsi:type="xsd:string">2017-11-09 15:37:05</value> </item> </value> </item> </callReturn> </ns1:callResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> 我想收到一个像这样的简单 JSON 对象: { "store_id": "1", "created_at": "2013-03-05 05:56:35", "updated_at": "2017-11-09 15:37:05", "shipping_address": { "address_id": "1", "created_at": "2013-01-31 11:37:38", "updated_at": "2017-11-09 15:37:05" } } 如果您使用的是 Java 8 或更高版本,您应该查看我的开源库:unXml。 unXml 基本上从 Xpath 映射到 Json 属性。 它可以在 Maven Central 上找到。 示例 import com.fasterxml.jackson.databind.node.ObjectNode; import com.nerdforge.unxml.factory.ParsingFactory; import com.nerdforge.unxml.parsers.Parser; import org.w3c.dom.Document; public class Parser { public ObjectNode parseXml(String xml){ Parsing parsing = ParsingFactory.getInstance().create(); Document document = parsing.xml().document(xml); Parser<ObjectNode> parser = parsing.obj() .attribute("store_id", "//item[key/text() = 'store_id']/value") .attribute("created_at", "//item[key/text() = 'created_at']/value") .attribute("updated_at", "//item[key/text() = 'updated_at']/value") .attribute("shipping_address", parsing.obj("//item[key/text() = 'shipping_address']") .attribute("address_id", "value/item[key/text() = 'address_id']/value") .attribute("created_at", "value/item[key/text() = 'created_at']/value") .attribute("updated_at", "value/item[key/text() = 'updated_at']/value") ) .build(); ObjectNode result = parser.apply(document); return result; } } 它将返回一个 Jackson ObjectNode,带有以下 json: { "created_at": "2013-03-05 05:56:35", "shipping_address": { "created_at": "2013-01-31 11:37:38", "address_id": "1", "updated_at": "2017-11-09 15:37:05" }, "store_id": "1", "updated_at": "2017-11-09 15:37:05" } public static JSONObject readToJSONObject(String xmlBody) { SAXReader saxReader = new SAXReader(); try { Document document = saxReader.read(new ByteArrayInputStream(xmlBody.getBytes())); Element rootElement = document.getRootElement(); JSONObject jsonObject = new JSONObject(); doParse(jsonObject, rootElement); return jsonObject; } catch (DocumentException e) { e.printStackTrace(); return null; } } public static void doParse(JSONObject jsonObject, Element element) { String elementName = element.getName(); List<Element> elements = element.elements(); if (CollectionUtils.isEmpty(elements)) { jsonObject.put(elementName, element.getText()); } else { JSONObject itemJsonObject = new JSONObject(); for (Element itemElement : elements) { doParse(itemJsonObject, itemElement); } jsonObject.put(elementNmae, itemJsonObject); } } 使用 readToJSONObject(xmlBody) 你可以使用这个库https://github.com/stleary/JSON-java/blob/master/src/main/java/org/json/XML.java 然后解析部分 SOAP Response 来获取 json 数据: import org.json.JSONObject; import org.json.XML; public class Main { public static void main(String[] args) { try { JSONObject jsonObj = XML.toJSONObject(XML_STRING); } catch (JSONException e) { System.out.println(e.toString()); } } }

回答 3 投票 0

SOAP-错误:解析 WSDL:无法从 'xxx/?wsdl' 加载:标签 html 第 1 行中的数据过早结束

几天来,我遇到了一个错误,但无法找到解决方案来解决此问题。 WSDL...

回答 1 投票 0

向 Spring Boot 中的某个 URL 发送 SOAP 请求

我正在尝试从我的 Spring Boot 应用程序向 SOAP API 发送请求。我生成的请求对象以 等标签开头和结尾。但我不断从 API 收到错误消息...

回答 1 投票 0

Python - 带标头和时间戳的 Zeep SOAP 请求

我正在尝试使用 Zeep 从 wsdl url 获取响应 需要用户名、密码、随机数 (PasswordDigest)、时间戳和标头。 这一切在 SoapUI 中工作正常,但我无法让它在 Z 中工作......

回答 1 投票 0

从 Oracle pl/sql 调用 Soap Web 服务出现错误

当我调用 SOAP 服务时,出现“ORA-29266:已到达正文末尾”错误。我使用公共测试 api 测试我的脚本”,例如 http://www.dataaccess.com/webservicesserver/NumberConversion.wso&qu...

回答 1 投票 0

将SoapHeader添加到org.springframework.ws.WebServiceMessage

如何将对象添加到 org.springframework.ws.WebServiceMessage 的肥皂头中 这是我希望最终得到的结构: 如何将对象添加到org.springframework.ws.WebServiceMessage的soap标头中 这是我希望最终得到的结构: <soap:Header> <credentials xmlns="http://example.com/auth"> <username>username</username> <password>password</password> </credentials> </soap:Header> 基本上,您需要在客户端中使用 WebServiceMessageCallback 在消息创建之后、发送之前修改消息。 @skaffman 已经非常准确地描述了其余代码,因此整个内容可能如下所示: public void marshalWithSoapActionHeader(MyObject o) { webServiceTemplate.marshalSendAndReceive(o, new WebServiceMessageCallback() { public void doWithMessage(WebServiceMessage message) { try { SoapMessage soapMessage = (SoapMessage)message; SoapHeader header = soapMessage.getSoapHeader(); StringSource headerSource = new StringSource("<credentials xmlns=\"http://example.com/auth\">\n + <username>"+username+"</username>\n + <password>"+password"+</password>\n + </credentials>"); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.transform(headerSource, header.getResult()); } catch (Exception e) { // exception handling } } }); } 就我个人而言,我发现 Spring-WS 很难满足这样的基本需求,他们应该修复 SWS-479。 您可以执行以下操作: public class SoapRequestHeaderModifier implements WebServiceMessageCallback { private final String userName = "user"; private final String passWd = "passwd"; @Override public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException { if (message instanceof SaajSoapMessage) { SaajSoapMessage soapMessage = (SaajSoapMessage) message; MimeHeaders mimeHeader = soapMessage.getSaajMessage().getMimeHeaders(); mimeHeader.setHeader("Authorization", getB64Auth(userName, passWd)); } } private String getB64Auth(String login, String pass) { String source = login + ":" + pass; String retunVal = "Basic " + Base64.getUrlEncoder().encodeToString(source.getBytes()); return retunVal; } } 然后 Object response = getWebServiceTemplate().marshalSendAndReceive(request, new SoapRequestHeaderModifier()); 您需要将 WebServiceMessage 转换为 SoapMessage,其中有一个 getSoapHeader() 方法可用于修改标题。反过来,SoapHeader有各种添加元素的方法,包括getResult()(可以用作Transformer.transform()操作的输出)。 I tried many options and finally below one worked for me if you have to send soap header with authentication(Provided authentication object created by wsimport) and also need to set soapaction. public Response callWebService(String url, Object request) { Response res = null; log.info("The request object is " + request.toString()); try { res = (Response) getWebServiceTemplate().marshalSendAndReceive(url, request,new WebServiceMessageCallback() { @Override public void doWithMessage(WebServiceMessage message) { try { // get the header from the SOAP message SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader(); // create the header element ObjectFactory factory = new ObjectFactory(); Authentication auth = factory.createAuthentication(); auth.setUser("****"); auth.setPassword("******"); ((SoapMessage) message).setSoapAction( "soapAction"); JAXBElement<Authentication> headers = factory.createAuthentication(auth); // create a marshaller JAXBContext context = JAXBContext.newInstance(Authentication.class); Marshaller marshaller = context.createMarshaller(); // marshal the headers into the specified result marshaller.marshal(headers, soapHeader.getResult()); } catch (Exception e) { log.error("error during marshalling of the SOAP headers", e); } } }); } catch (Exception e) { e.printStackTrace(); } return res; } 您也可以通过创建子元素的键值映射来实现: final Map<String, String> elements = new HashMap<>(); elements.put("username", "username"); elements.put("password", "password"); 在soap标头中设置子元素的命名空间和前缀: final String LOCAL_NAME = "credentials"; final String PREFIX = ""; final String NAMESPACE = "http://example.com/auth"; 然后,您可以调用 WebServiceTemplate 的方法 marshalSendAndReceive,在其中重写 WebServiceMessageCallback 的方法 doWithMessage,如下所示: Object response = getWebServiceTemplate().marshalSendAndReceive(request, (message) -> { if (message instanceof SaajSoapMessage) { SaajSoapMessage saajSoapMessage = (SaajSoapMessage) message; SOAPMessage soapMessage = saajSoapMessage.getSaajMessage(); SOAPPart soapPart = soapMessage.getSOAPPart(); if (Objects.nonNull(elements)) { try { SOAPEnvelope soapEnvelope = soapPart.getEnvelope(); SOAPHeader soapHeader = soapEnvelope.getHeader(); Name headerElementName = soapEnvelope.createName( LOCAL_NAME, PREFIX, NAMESPACE ); SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(headerElementName); elements.forEach((key, value) -> { try { SOAPElement element = soapHeaderElement.addChildElement(key, PREFIX); element.addTextNode(value); } catch (SOAPException e) { // error handling } }); soapMessage.saveChanges(); } catch (SOAPException e) { // error handling } } } }); 上述步骤导致: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <credentials xmlns="http://example.com/auth"> <password>password</password> <username>username</username> </credentials> </env:Header> <env:Body> <!-- your payload --> </env:Body> </env:Envelope> Response response = (Response)getWebServiceTemplate() .marshalSendAndReceive(request, new HeaderModifier()); 创建类 HeaderModifier 并重写 doWithMessage public class HeaderModifier implements WebServiceMessageCallback { private static PrintStream out = System.out; @Override public void doWithMessage(WebServiceMessage message) throws IOException { SaajSoapMessage soapMessage = (SaajSoapMessage) message; SoapEnvelope soapEnvelope = soapMessage.getEnvelope(); SoapHeader soapHeader = soapEnvelope.getHeader(); //Initialize QName for Action and To QName action = new QName("{uri}","Action","{actionname}"); QName to = new QName("{uri}","To","{actionname}"); soapHeader.addNamespaceDeclaration("{actionname}", "{uri}"); SoapHeaderElement soapHeaderElementAction = soapHeader.addHeaderElement(action); SoapHeaderElement soapHeaderElementTo = soapHeader.addHeaderElement(to); soapHeaderElementAction.setText("{text inside the tags}"); soapHeaderElementTo.setText("{text inside the tags}"); soapMessage.setSoapAction("{add soap action uri}"); soapMessage.writeTo(out); } }

回答 6 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.