我有一个zeep显示为没有任何操作的WSDL,但是当我在浏览器中将其拉出时,WSDL中有一些操作。作为参考,WSDL需要证书。 WSDL:
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete" xmlns:ns2="http://schemas.xmlsoap.org/wsdl/http/" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns4="http://www.w3.org/2006/05/addressing/wsdl" xmlns:ns3="http://schemas.xmlsoap.org/wsdl/jms/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete" xmlns:ns0="http://www.ercot.com/schema/2007-06/nodal/ews/message" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsse="http://www.docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsp:UsingPolicy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" wsdl:Required="true" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/>
<wsp:Policy xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"><sp:SecurityHeader MustManifestEncryption="true" MustPrepend="true" xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"/></wsp:Policy>
<wsp:Policy wsu:Id="SecurityTokens" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:ExactlyOne><wsp:All><sp:SecurityToken xmlns:_ns1="http://www.actional.com" xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"><sp:TokenType>_ns1:SSLClientCertificate</sp:TokenType></sp:SecurityToken></wsp:All><wsp:All><sp:SecurityToken xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"><sp:TokenType>sp:X509v3</sp:TokenType></sp:SecurityToken></wsp:All><wsp:All><sp:SecurityToken xmlns:_ns1="http://www.actional.com" xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"><sp:TokenType>_ns1:SSLClientCertificate</sp:TokenType></sp:SecurityToken><sp:SecurityToken xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"><sp:TokenType>sp:X509v3</sp:TokenType></sp:SecurityToken></wsp:All></wsp:ExactlyOne></wsp:Policy>
<wsp:Policy wsu:Id="SignedBody" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><sp:Integrity xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"><sp:TokenInfo><sp:SecurityToken><sp:TokenType>sp:X509v3</sp:TokenType></sp:SecurityToken></sp:TokenInfo><sp:MessageParts>wsp:GetBody(.)</sp:MessageParts></sp:Integrity></wsp:Policy>
<wsp:Policy wsu:Id="Alerts_input_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SecurityTokens"/><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<wsp:Policy wsu:Id="Alerts_output_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<wsp:Policy wsu:Id="MarketInfo_input_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SecurityTokens"/><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<wsp:Policy wsu:Id="MarketInfo_output_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<wsp:Policy wsu:Id="MarketTransactions_input_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SecurityTokens"/><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<wsp:Policy wsu:Id="MarketTransactions_output_policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsp:PolicyReference URI="#SignedBody"/></wsp:Policy>
<types>
<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RequestType">
<xsd:sequence>
<xsd:element minOccurs="0" name="MarketType">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="DAM"/>
<xsd:enumeration value="ADJ"/>
<xsd:enumeration value="RTM"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element minOccurs="0" name="OperatingDate" type="xsd:dateTime"/>
<xsd:element minOccurs="0" name="TradingDate" type="xsd:date"/>
<xsd:element minOccurs="0" name="StartTime" type="xsd:dateTime"/>
<xsd:element minOccurs="0" name="EndTime" type="xsd:dateTime"/>
<xsd:element minOccurs="0" name="Zone" type="xsd:string"/>
<xsd:element minOccurs="0" name="ASType" type="xsd:string"/>
<xsd:element minOccurs="0" name="Option" type="xsd:string"/>
<xsd:element minOccurs="0" name="SortBy" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="ID" type="xsd:string"/>
<xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##other"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ReplyType">
<xsd:sequence>
<xsd:element name="ReplyCode" type="xsd:string"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Error" type="xsd:string"/>
<xsd:element minOccurs="0" name="Timestamp" type="xsd:dateTime"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="ID" type="xsd:string"/>
<xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##other"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="PayloadType">
<xsd:sequence>
<xsd:choice>
<xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##other" processContents="skip"/>
<xsd:element maxOccurs="unbounded" minOccurs="0" name="Document" type="xsd:string"/>
<xsd:element minOccurs="0" name="Compressed" type="xsd:string"/>
</xsd:choice>
<xsd:element minOccurs="0" name="format" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ReplayDetectionType">
<xsd:sequence>
<xsd:element name="Nonce" type="wsse:EncodedString"/>
<xsd:element name="Created" type="wsu:AttributedDateTime"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HeaderType">
<xsd:sequence>
<xsd:element default="get" name="Verb">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="cancel"/>
<xsd:enumeration value="canceled"/>
<xsd:enumeration value="change"/>
<xsd:enumeration value="changed"/>
<xsd:enumeration value="create"/>
<xsd:enumeration value="created"/>
<xsd:enumeration value="close"/>
<xsd:enumeration value="closed"/>
<xsd:enumeration value="delete"/>
<xsd:enumeration value="deleted"/>
<xsd:enumeration value="get"/>
<xsd:enumeration value="reply"/>
<xsd:enumeration value="submit"/>
<xsd:enumeration value="update"/>
<xsd:enumeration value="updated"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Noun" type="xsd:string"/>
<xsd:element name="ReplayDetection" type="ReplayDetectionType"/>
<xsd:element default="001" name="Revision" type="xsd:string"/>
<xsd:element name="Source" type="xsd:string"/>
<xsd:element minOccurs="0" name="UserID" type="xsd:string"/>
<xsd:element minOccurs="0" name="MessageID" type="xsd:string"/>
<xsd:element minOccurs="0" name="Comment" type="xsd:string"/>
<xsd:any maxOccurs="unbounded" minOccurs="0" namespace="##other"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Message">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Header" type="HeaderType"/>
<xsd:choice>
<xsd:element minOccurs="0" name="Request" type="RequestType"/>
<xsd:element minOccurs="0" name="Reply" type="ReplyType"/>
</xsd:choice>
<xsd:element minOccurs="0" name="Payload" type="PayloadType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="RequestMessage">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Header" type="HeaderType"/>
<xsd:element minOccurs="0" name="Request" type="RequestType"/>
<xsd:element minOccurs="0" name="Payload" type="PayloadType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ResponseMessage">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Header" type="HeaderType"/>
<xsd:element minOccurs="0" name="Reply" type="ReplyType"/>
<xsd:element minOccurs="0" name="Payload" type="PayloadType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="FaultMessage">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="0" name="Reply" type="ReplyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</types>
<message name="EWSRequest">
<part name="input" element="ns0:RequestMessage"/>
</message>
<message name="EWSResponse">
<part name="output" element="ns0:ResponseMessage"/>
</message>
<message name="EWSFault">
<part name="fault" element="ns0:FaultMessage"/>
</message>
<portType name="Operations">
<operation name="MarketTransactions">
<input message="tns:EWSRequest"/>
<output message="tns:EWSResponse"/>
<fault name="fault1" message="tns:EWSFault"/>
</operation>
<operation name="Alerts">
<input message="tns:EWSRequest"/>
<output message="tns:EWSResponse"/>
<fault name="fault1" message="tns:EWSFault"/>
</operation>
<operation name="MarketInfo">
<input message="tns:EWSRequest"/>
<output message="tns:EWSResponse"/>
<fault name="fault1" message="tns:EWSFault"/>
</operation>
</portType>
<binding name="HttpEndPointBinding" type="tns:Operations">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="MarketTransactions">
<soap:operation soapAction="/BusinessService/NodalService.serviceagent/HttpEndPoint/MarketTransactions" style="document"/>
<input>
<soap:body parts="input" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#MarketTransactions_input_policy"/>
</input>
<output>
<soap:body parts="output" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#MarketTransactions_output_policy"/>
</output>
<fault name="fault1">
<soap:fault name="fault1" use="literal"/>
</fault>
</operation>
<operation name="MarketInfo">
<soap:operation soapAction="/BusinessService/NodalService.serviceagent/HttpEndPoint/MarketInfo" style="document"/>
<input>
<soap:body parts="input" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#MarketInfo_input_policy"/>
</input>
<output>
<soap:body parts="output" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#MarketInfo_output_policy"/>
</output>
<fault name="fault1">
<soap:fault name="fault1" use="literal"/>
</fault>
</operation>
<operation name="Alerts">
<soap:operation soapAction="/BusinessService/NodalService.serviceagent/HttpEndPoint/Alerts" style="document"/>
<input>
<soap:body parts="input" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#Alerts_input_policy"/>
</input>
<output>
<soap:body parts="output" use="literal"/>
<wsp:PolicyReference xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" URI="#Alerts_output_policy"/>
</output>
<fault name="fault1">
<soap:fault name="fault1" use="literal"/>
</fault>
</operation>
</binding>
<service name="NodalService">
<port name="HttpEndPoint" binding="tns:HttpEndPointBinding">
<soap:address location="http://prl0161.ercot.com:8090/sst/runtime.asvc/com.ercot.eip.EWSExtHTTP"/>
</port>
</service>
</definitions>
我使用SOAPUI来测试WSDL,并且所有操作都被识别出来,没有任何问题,但是在python中,有一堆关于无效xsd类型的警告。我对WSDL / XML缺乏经验,所以这些对我来说意义不大。我的代码如下:
import random
from requests import Session
from zeep import Client , Settings
from zeep.transports import Transport
from zeep.wsse.signature import Signature
from suds.wsse import Timestamp
import operator
wsdl_url = r"https://misapi.ercot.com/2007-08/Nodal/eEDS/EWS/?WSDL"
api_base_url = "https://misapi.ercot.com/2007-08/Nodal/eEDS/EWS/"
client_cert_pfx ='pfx path'
client_cert_pem = 'pem path'
keyfile = 'key'
certfile = 'cert'
##############################################################################
def get_random_number():
rand_numb = random.randint(1000000000000000,9999999999999999)
return rand_numb
##############################################################################
session = Session()
session.cert = client_cert_pem
transport = Transport(session=session)
signature = Signature(key_file=keyfile, certfile=certfile)
client = Client(
wsdl=wsdl_url,
transport=transport,
wsse=signature
)
request_data = {
"Header": {
"Verb": "get",
"Noun": "SystemStatus",
"ReplayDetection": {
"Nonce": get_random_number(),
"Created": Timestamp().created},
"Revision": "01",
"Source": api_base_url,
"UserID": "UserID",
"MessageID": "00000000000",
"Comment": "00000000000",
},
}
#Code Below is from https://stackoverflow.com/questions/50089400/introspecting-a-wsdl-with-# python-zeep
for service in client.wsdl.services.values():
print("service:", service.name)
for port in service.ports.values():
operations = sorted(
port.binding._operations.values(),
key=operator.attrgetter('name'))
for operation in operations:
print("method :", operation.name)
print(" input :", operation.input.signature())
print()
print()
输出:
C:\path
-packages\zeep\wsdl\wsdl.py:338: UserWarning: The wsdl:message for '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}EWSRequest' contains an invalid part ('input'): invalid xsd type or elements
warnings.warn(str(exc))
C:\path
-packages\zeep\wsdl\wsdl.py:338: UserWarning: The wsdl:message for '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}EWSResponse' contains an invalid part ('output'): invalid xsd type or elements
warnings.warn(str(exc))
C:\path
-packages\zeep\wsdl\wsdl.py:338: UserWarning: The wsdl:message for '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}EWSFault' contains an invalid part ('fault'): invalid xsd type or elements
warnings.warn(str(exc))
service: NodalService
C:\path
-packages\zeep\wsdl\definitions.py:137: UserWarning: The wsdl:operation 'MarketTransactions' was not found in the wsdl:portType '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}Operations'
warnings.warn(str(exc))
C:\path
-packages\zeep\wsdl\definitions.py:137: UserWarning: The wsdl:operation 'MarketInfo' was not found in the wsdl:portType '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}Operations'
warnings.warn(str(exc))
C:\path
-packages\zeep\wsdl\definitions.py:137: UserWarning: The wsdl:operation 'Alerts' was not found in the wsdl:portType '{http://www.ercot.com/wsdl/2007-06/nodal/ewsConcrete}Operations'
warnings.warn(str(exc))
Forcing soap:address location to HTTPS
Process finished with exit code 0