Soap - Umbau

Sasser

Erfahrenes Mitglied
Guten Abend!

Ich möchte gern das folgende SOAP-Beispiel so umbauen, sodass keine SOAP-Klasse notwendig ist. Daher meine Frage; Welche Möglichkeiten gibt es noch mit der API zu kommunizieren? Funktioniert dies auch per CURL und dann SIMPLE_XML_LOAD? Ich wäre sehr über einen kleinen Lösungsansatz erfreut.

PHP:
define ("WSDL_LOGON", "https://api.affili.net/V2.0/Logon.svc?wsdl");
define ("WSDL_PROD",  "https://api.affili.net/V2.0/ProductServices.svc?wsdl");

$Username   = "username";
$Password   = "password";
 
$SOAP_LOGON = new SoapClient(WSDL_LOGON);
$Token      = $SOAP_LOGON->Logon(array(
              'Username'  => $Username,
              'Password'  => $Password,
              'WebServiceType' => 'Product'
              ));

$SOAP_REQUEST = new SoapClient(WSDL_PROD);
$req = $SOAP_REQUEST->GetShopList(array(
             'CredentialToken' => $Token
             ));
 
print_r($req);
 
Da nur SOAP funktioniert, werde ich wohl nicht um SOAP herum kommen.

Gibt es fertige SOAP - Klassen, welche mal einbinden kann ohne PHP gleich neu kompilieren zu müssen, sodass mir die SOAP-Klasse zur Verfügung steht?

Nach langem Suchen, konnte ich keine passende Klasse finden...
 
Ich habe nun einmal per simplexml_load_file die Parameter zu übergeben und dann den Rückgabewert auszugeben, jedoch scheint das nicht ganz zu funktionieren... Was mache ich falsch?

PHP:
$res = simplexml_load_file ( "https://api.affili.net/V2.0/Logon.svc?wsdl" . "&Username=" . $Username . "&Password=" . $Password . "&WebServiceType=Product" );
print_r ( $res );
 
Eindlich habe ich einen kleinen Teilerfolg. Ich habe nun einen SOAP-Request per Curl abgesetzt:

PHP:
$WSDL_URL = "https://api.affili.net/V2.0/Logon.svc?wsdl";

$requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
	<Logon xmlns="https://api.affili.net/V2.0/Logon.svc?wsdl">
      <Username>' . $Username . '</Username>
      <Password>' . $Password . '</Password>
      <WebServiceType>Product</WebServiceType>
    </Logon>
  </soap:Body>
</soap:Envelope>';

$connection = curl_init ();
curl_setopt ( $connection, CURLOPT_URL, $WSDL_URL );
curl_setopt ( $connection, CURLOPT_SSL_VERIFYPEER, "0" );
curl_setopt ( $connection, CURLOPT_SSL_VERIFYHOST, "0" );
curl_setopt ( $connection, CURLOPT_HTTPHEADER, array ( "Content-Type: text/xml; charset=utf-8" ) );
curl_setopt ( $connection, CURLOPT_POST, true );
curl_setopt ( $connection, CURLOPT_POSTFIELDS, $requestXmlBody );
curl_setopt ( $connection, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec ( $connection );
curl_close ( $connection );

print_r ( $response );

Eine Antwort sieht folgendermaßen aus, wenn ich die Schnittstelle im Browser aufrufe:

Code:
<wsdl:definitions name="Authentication" targetNamespace="http://affilinet.framework.webservices/Svc">
?
<wsp:Policy wsu:Id="DefaultEndpointLogon_policy">
?
<wsp:ExactlyOne>
?
<wsp:All>
?
<sp:TransportBinding>
?
<wsp:Policy>
?
<sp:TransportToken>
?
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
?
<sp:AlgorithmSuite>
?
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
?
<sp:Layout>
?
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
?
<wsdl:types>
?
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/">
<xs:element name="anyType" nillable="true" type="xs:anyType"/>
<xs:element name="anyURI" nillable="true" type="xs:anyURI"/>
<xs:element name="base64Binary" nillable="true" type="xs:base64Binary"/>
<xs:element name="boolean" nillable="true" type="xs:boolean"/>
<xs:element name="byte" nillable="true" type="xs:byte"/>
<xs:element name="dateTime" nillable="true" type="xs:dateTime"/>
<xs:element name="decimal" nillable="true" type="xs:decimal"/>
<xs:element name="double" nillable="true" type="xs:double"/>
<xs:element name="float" nillable="true" type="xs:float"/>
<xs:element name="int" nillable="true" type="xs:int"/>
<xs:element name="long" nillable="true" type="xs:long"/>
<xs:element name="QName" nillable="true" type="xs:QName"/>
<xs:element name="short" nillable="true" type="xs:short"/>
<xs:element name="string" nillable="true" type="xs:string"/>
<xs:element name="unsignedByte" nillable="true" type="xs:unsignedByte"/>
<xs:element name="unsignedInt" nillable="true" type="xs:unsignedInt"/>
<xs:element name="unsignedLong" nillable="true" type="xs:unsignedLong"/>
<xs:element name="unsignedShort" nillable="true" type="xs:unsignedShort"/>
<xs:element name="char" nillable="true" type="tns:char"/>
?
<xs:simpleType name="char">
<xs:restriction base="xs:int"/>
</xs:simpleType>
<xs:element name="duration" nillable="true" type="tns:duration"/>
?
<xs:simpleType name="duration">
?
<xs:restriction base="xs:duration">
<xs:pattern value="\-?P(\d*D)?(T(\d*H)?(\d*M)?(\d*(\.\d*)?S)?)?"/>
<xs:minInclusive value="-P10675199DT2H48M5.4775808S"/>
<xs:maxInclusive value="P10675199DT2H48M5.4775807S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="guid" nillable="true" type="tns:guid"/>
?
<xs:simpleType name="guid">
?
<xs:restriction base="xs:string">
<xs:pattern value="[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="FactoryType" type="xs:QName"/>
<xs:attribute name="Id" type="xs:ID"/>
<xs:attribute name="Ref" type="xs:IDREF"/>
</xs:schema>
?
<xsd:schema elementFormDefault="qualified" targetNamespace="http://affilinet.framework.webservices/types">
?
<xsd:complexType name="Logon">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="Username" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="Password" nillable="true" type="xsd:string"/>
<xsd:element name="WebServiceType" type="tns:WebServiceTypes"/>
<xsd:element minOccurs="0" name="DeveloperSettings" nillable="true" type="tns:TokenDeveloperDetails"/>
<xsd:element minOccurs="0" name="ApplicationSettings" nillable="true" type="tns:TokenApplicationDetails"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="Logon" nillable="true" type="tns:Logon"/>
?
<xsd:simpleType name="WebServiceTypes">
?
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Product"/>
<xsd:enumeration value="Publisher"/>
</xsd:restriction>
</xsd:simpleType>
<xsd:element name="WebServiceTypes" nillable="true" type="tns:WebServiceTypes"/>
?
<xsd:complexType name="TokenDeveloperDetails">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="SandboxPublisherID" nillable="true" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TokenDeveloperDetails" nillable="true" type="tns:TokenDeveloperDetails"/>
?
<xsd:complexType name="TokenApplicationDetails">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="ApplicationID" nillable="true" type="xsd:int"/>
<xsd:element minOccurs="0" name="DeveloperID" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="TokenApplicationDetails" nillable="true" type="tns:TokenApplicationDetails"/>
?
<xsd:complexType name="affilinetWebserviceFault">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="ErrorMessages" nillable="true" type="q1:ArrayOfKeyValueOfstringstring"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="affilinetWebserviceFault" nillable="true" type="tns:affilinetWebserviceFault"/>
</xsd:schema>
?
<xsd:schema elementFormDefault="qualified" targetNamespace="http://affilinet.framework.webservices/Svc">
<xsd:element name="LogonRequestMsg" nillable="true" type="q2:Logon"/>
<xsd:element name="CredentialToken" nillable="true" type="xsd:string"/>
<xsd:element name="ExpirationDate" type="xsd:dateTime"/>
</xsd:schema>
?
<xsd:schema elementFormDefault="qualified" targetNamespace="http://www.microsoft.com/practices/EnterpriseLibrary/2007/01/wcf/validation">
?
<xsd:complexType name="ValidationFault">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="Details" nillable="true" type="q3:ArrayOfValidationDetail"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ValidationFault" nillable="true" type="tns:ValidationFault"/>
</xsd:schema>
?
<xsd:schema elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WCF">
?
<xsd:complexType name="ArrayOfValidationDetail">
?
<xsd:sequence>
<xsd:element minOccurs="0" maxOccurs="unbounded" name="ValidationDetail" nillable="true" type="tns:ValidationDetail"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ArrayOfValidationDetail" nillable="true" type="tns:ArrayOfValidationDetail"/>
?
<xsd:complexType name="ValidationDetail">
?
<xsd:sequence>
<xsd:element minOccurs="0" name="Key" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="Message" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="Tag" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ValidationDetail" nillable="true" type="tns:ValidationDetail"/>
</xsd:schema>
?
<xsd:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
?
<xsd:complexType name="ArrayOfKeyValueOfstringstring">
?
<xsd:annotation>
?
<xsd:appinfo>
<IsDictionary>true</IsDictionary>
</xsd:appinfo>
</xsd:annotation>
?
<xsd:sequence>
?
<xsd:element minOccurs="0" maxOccurs="unbounded" name="KeyValueOfstringstring">
?
<xsd:complexType>
?
<xsd:sequence>
<xsd:element name="Key" nillable="true" type="xsd:string"/>
<xsd:element name="Value" nillable="true" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ArrayOfKeyValueOfstringstring" nillable="true" type="tns:ArrayOfKeyValueOfstringstring"/>
</xsd:schema>
</wsdl:types>
?
<wsdl:message name="LogonRequest">
<wsdl:part name="LogonRequestMsg" element="tns:LogonRequestMsg"/>
</wsdl:message>
?
<wsdl:message name="LogonResponse">
<wsdl:part name="CredentialToken" element="tns:CredentialToken"/>
</wsdl:message>
?
<wsdl:message name="AuthenticationContract_Logon_ValidationFaultFault_FaultMessage">
<wsdl:part name="detail" element="q4:ValidationFault"/>
</wsdl:message>
?
<wsdl:message name="AuthenticationContract_Logon_affilinetWebserviceFaultFault_FaultMessage">
<wsdl:part name="detail" element="q5:affilinetWebserviceFault"/>
</wsdl:message>
?
<wsdl:message name="GetIdentifierExpirationRequest">
<wsdl:part name="CredentialToken" element="tns:CredentialToken"/>
</wsdl:message>
?
<wsdl:message name="GetIdentifierExpirationResponse">
<wsdl:part name="ExpirationDate" element="tns:ExpirationDate"/>
</wsdl:message>
?
<wsdl:message name="AuthenticationContract_GetIdentifierExpiration_ValidationFaultFault_FaultMessage">
<wsdl:part name="detail" element="q6:ValidationFault"/>
</wsdl:message>
?
<wsdl:message name="AuthenticationContract_GetIdentifierExpiration_affilinetWebserviceFaultFault_FaultMessage">
<wsdl:part name="detail" element="q7:affilinetWebserviceFault"/>
</wsdl:message>
?
<wsdl:portType name="AuthenticationContract">
?
<wsdl:operation name="Logon">
<wsdl:input wsaw:Action="http://affilinet.framework.webservices/Svc/ServiceContract1/Logon" name="LogonRequest" message="tns:LogonRequest"/>
<wsdl:output wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/LogonResponse" name="LogonResponse" message="tns:LogonResponse"/>
<wsdl:fault wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/LogonValidationFaultFault" name="ValidationFaultFault" message="tns:AuthenticationContract_Logon_ValidationFaultFault_FaultMessage"/>
<wsdl:fault wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/LogonaffilinetWebserviceFaultFault" name="affilinetWebserviceFaultFault" message="tns:AuthenticationContract_Logon_affilinetWebserviceFaultFault_FaultMessage"/>
</wsdl:operation>
?
<wsdl:operation name="GetIdentifierExpiration">
<wsdl:input wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/GetIdentifierExpiration" name="GetIdentifierExpirationRequest" message="tns:GetIdentifierExpirationRequest"/>
<wsdl:output wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/GetIdentifierExpirationResponse" name="GetIdentifierExpirationResponse" message="tns:GetIdentifierExpirationResponse"/>
<wsdl:fault wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/GetIdentifierExpirationValidationFaultFault" name="ValidationFaultFault" message="tns:AuthenticationContract_GetIdentifierExpiration_ValidationFaultFault_FaultMessage"/>
<wsdl:fault wsaw:Action="http://affilinet.framework.webservices/Svc/AuthenticationContract/GetIdentifierExpirationaffilinetWebserviceFaultFault" name="affilinetWebserviceFaultFault" message="tns:AuthenticationContract_GetIdentifierExpiration_affilinetWebserviceFaultFault_FaultMessage"/>
</wsdl:operation>
</wsdl:portType>
?
<wsdl:binding name="DefaultEndpointLogon" type="tns:AuthenticationContract">
<wsp:PolicyReference URI="#DefaultEndpointLogon_policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
?
<wsdl:operation name="Logon">
<soap:operation soapAction="http://affilinet.framework.webservices/Svc/ServiceContract1/Logon" style="document"/>
?
<wsdl:input name="LogonRequest">
<soap:body use="literal"/>
</wsdl:input>
?
<wsdl:output name="LogonResponse">
<soap:body use="literal"/>
</wsdl:output>
?
<wsdl:fault name="ValidationFaultFault">
<soap:fault name="ValidationFaultFault" use="literal"/>
</wsdl:fault>
?
<wsdl:fault name="affilinetWebserviceFaultFault">
<soap:fault name="affilinetWebserviceFaultFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
?
<wsdl:operation name="GetIdentifierExpiration">
<soap:operation soapAction="http://affilinet.framework.webservices/Svc/AuthenticationContract/GetIdentifierExpiration" style="document"/>
?
<wsdl:input name="GetIdentifierExpirationRequest">
<soap:body use="literal"/>
</wsdl:input>
?
<wsdl:output name="GetIdentifierExpirationResponse">
<soap:body use="literal"/>
</wsdl:output>
?
<wsdl:fault name="ValidationFaultFault">
<soap:fault name="ValidationFaultFault" use="literal"/>
</wsdl:fault>
?
<wsdl:fault name="affilinetWebserviceFaultFault">
<soap:fault name="affilinetWebserviceFaultFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
?
<wsdl:service name="Authentication">
?
<wsdl:port name="DefaultEndpointLogon" binding="tns:DefaultEndpointLogon">
<soap:address location="https://api.affili.net/V2.0/Logon.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Ich bekomme allerdings den folgenden Error zurück:

Code:
<s:Envelope>
<s:Body>
<s:Fault>
<faultcode>a:ActionNotSupported</faultcode>
<faultstring xml:lang="en-US">
The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).
</faultstring>
</s:Fault>
</s:Body>
</s:Envelope>

Was mache ich nur ständig falsch? Ich versuche schon den ganzen Tag, einen Erfolg zu erzielen, jedoch immer der selbe Fehler...
 
Zuletzt bearbeitet:
Hi,

versuch es mal indem du im HTTP-Header noch die SOAPAction setzt. In deinem fall müsste das vermutlich so aussehen:

PHP:
curl_setopt ( $connection, CURLOPT_HTTPHEADER, array ( "Content-Type: text/xml; charset=utf-8", "SOAPAction: http://affilinet.framework.webservices/Svc/ServiceContract1/Logon" ) );
 
Zuletzt bearbeitet:
Der Fehler ist nun verschwunden, jedoch erhalte ich nun einen neuen Fehler:

Code:
<s:Envelope>
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring xml:lang="en-US">
Object reference not set to an instance of an object.
</faultstring>
<detail>
<affilinetWebserviceFault>
<ErrorMessages>
<a:KeyValueOfstringstring>
<a:Key>10950100</a:Key>
<a:Value>
Object reference not set to an instance of an object.
</a:Value>
</a:KeyValueOfstringstring>
</ErrorMessages>
</affilinetWebserviceFault>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
 
Hi,

gibt es in der Doku vielleicht eine genauere Beschreibung dazu?

Das Attribut "xmlns" bei Logon kannst du glaub ich weglassen. Ich glaube der Wert ist 'eh nicht richtig.

Code:
<Logon xmlns="https://api.affili.net/V2.0/Logon.svc?wsdl">
 
Leider gibt es keine Anleitung dazu, sondern nur einen kleinen PHP-Schnipsel:

PHP:
$WSDL_URL = "https://api.affili.net/V2.0/Logon.svc?wsdl";
$SOAP_LOGON = new SoapClient ( $WSDL_URL );
$request = $SOAP_LOGON->Logon ( array ( "Username"  => $Username, "Password"  => $Password, "WebServiceType" => "Product" ) );

Wenn man die o.g. API aufruft, finde ich einen Teil, welcher mit dem Logon zu tun hat:

Code:
<xsd:schema elementFormDefault="qualified" targetNamespace="http://affilinet.framework.webservices/types">
<xsd:complexType name="Logon">
<xsd:sequence>
<xsd:element minOccurs="0" name="Username" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="Password" nillable="true" type="xsd:string"/>
<xsd:element name="WebServiceType" type="tns:WebServiceTypes"/>
</xsd:sequence>
</xsd:complexType>
 
Zuletzt bearbeitet:
Jo das ist der Datentyp (ComplexType) der bei einem Logon Request angegeben werden muss, aber das machst du ja bereits.

Dieser sagt aus das ein "Username(string)", "Password(string)" und ein Wert der Enumeration von "WebServiceType" (Product oder Publisher) gegeben sein muss.

Wird denn vielleicht eine Beispielapplikation angeboten wo du den Soap-Http-Request mit deinem eigenen vergleichen kannst?

Wie sieht es den eigentlich mit den Parametern "DeveloperSettings" und "ApplicationSettings" aus? Die hast du bisher ja noch gar nicht angegeben. Die WSD sagt zwar das es nicht unbedingt benötigt wird aber man weis ja nie.
 
Zuletzt bearbeitet:
Das ist ja mein Problem, dass kein Beispiel vorhanden ist. Man soll einfach die fertige Klasse SOAP nutzen, welche aber nicht bei jedem vorhanden ist...

Was kann ich nun noch machen, um den Fehler zu finden?

Mein Code sieht derzeit so aus:

PHP:
$WSDL_URL = "https://api.affili.net/V2.0/Logon.svc?wsdl";

$requestXmlBody = '<?xml version="1.0" encoding="utf-8"?>';
$requestXmlBody .= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
$requestXmlBody .= "<soap:Body>";
$requestXmlBody .= "<Logon>";
$requestXmlBody .= "<Username>" . $Username . "</Username>";
$requestXmlBody .= "<Password>" . $Password . "</Password>";
$requestXmlBody .= "<WebServiceType>Product</WebServiceType>";
$requestXmlBody .= "</Logon>";
$requestXmlBody .= "</soap:Body>";
$requestXmlBody .= "</soap:Envelope>";

$connection = curl_init ();
curl_setopt ( $connection, CURLOPT_URL, $WSDL_URL );
curl_setopt ( $connection, CURLOPT_SSL_VERIFYPEER, "0" );
curl_setopt ( $connection, CURLOPT_SSL_VERIFYHOST, "0" );
curl_setopt ( $connection, CURLOPT_HTTPHEADER, array ( "Content-Type: text/xml; charset=utf-8", "SOAPAction: http://affilinet.framework.webservices/Svc/ServiceContract1/Logon" ) );
curl_setopt ( $connection, CURLOPT_POST, true );
curl_setopt ( $connection, CURLOPT_POSTFIELDS, $requestXmlBody );
curl_setopt ( $connection, CURLOPT_RETURNTRANSFER, true );
$responseXmlBody = curl_exec ( $connection );
curl_close ( $connection );

Die zusätzlichen optionalen Parameter "DeveloperSettings" und "ApplicationSettings" habe ich auch bereits ausprobiert, ändert jedoch leider nichts an dem Fehler... :(
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück