#php #wcf #soap #wsdl
#php #wcf #soap #wsdl
Вопрос:
Я пытаюсь реализовать внешний SOAP API внутри нашего проекта.
Наша инициализация Soap-клиента в PHP 7.3 $serviceLocation
пробовала оба http://address.com/smsXMLWebService/SMSXMLWebService.svc
и http://address.com/smsXMLWebService/SMSXMLWebService.svc/basicHttp
$this->soapClient = new SoapClient(
$wsdlUri,
[
'connection_timeout' => $connectionTimeout,
'location' => $serviceLocation,
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE,
'stream_context' => $context,
'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
'trace' => true,
'verify_peer' => false,
'verify_host' => false,
]
);
выдает следующее исключение:
Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap xml; charset=utf-8'.
Результаты будут такими же, если мы установим Content-type по заголовку в контексте:
$options = [];
$options['http'] = [];
$options['http']['header'] = [];
$options['http']['header'][] = 'Content-type: application/soap xml; charset=utf-8';
$context = stream_context_create($options);
Если мы попытаемся 'soap_version' => SOAP_1_2
, мы получим следующее исключение:
Bad gateway
Это фрагмент из WSDL (мы не можем изменить WSDL на сервере)
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="SMSXMLWebService" targetNamespace="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy"
xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:tns="http://tempuri.org/"
xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata"
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"
xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsp:Policy wsu:Id="WSHttpBinding_ISMSXMLWebService_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:SymmetricBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:ProtectionToken>
<wsp:Policy>
<sp:SecureConversationToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:RequireDerivedKeys/>
<sp:BootstrapPolicy>
<wsp:Policy>
<sp:SignedParts>
<sp:Body/>
<sp:Header Name="To"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="From"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="FaultTo"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="ReplyTo"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="MessageID"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="RelatesTo"
Namespace="http://www.w3.org/2005/08/addressing"/>
<sp:Header Name="Action"
Namespace="http://www.w3.org/2005/08/addressing"/>
</sp:SignedParts>
<sp:EncryptedParts>
<sp:Body/>
</sp:EncryptedParts>
<sp:SymmetricBinding>
<wsp:Policy>
<sp:ProtectionToken>
<wsp:Policy>
<mssp:SslContextToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"
xmlns:mssp="http://schemas.microsoft.com/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:RequireDerivedKeys/>
</wsp:Policy>
</mssp:SslContextToken>
</wsp:Policy>
</sp:ProtectionToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:EncryptSignature/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:SymmetricBinding>
<sp:SignedSupportingTokens>
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
<sp:Wss11>
<wsp:Policy/>
</sp:Wss11>
<sp:Trust10>
<wsp:Policy>
<sp:MustSupportIssuedTokens/>
<sp:RequireClientEntropy/>
<sp:RequireServerEntropy/>
</wsp:Policy>
</sp:Trust10>
</wsp:Policy>
</sp:BootstrapPolicy>
</wsp:Policy>
</sp:SecureConversationToken>
</wsp:Policy>
</sp:ProtectionToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256/>
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:EncryptSignature/>
<sp:OnlySignEntireHeadersAndBody/>
</wsp:Policy>
</sp:SymmetricBinding>
<sp:Wss11 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy/>
</sp:Wss11>
<sp:Trust10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:MustSupportIssuedTokens/>
<sp:RequireClientEntropy/>
<sp:RequireServerEntropy/>
</wsp:Policy>
</sp:Trust10>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsp:Policy wsu:Id="BasicHttpBinding_ISMSXMLWebService_policy">
<wsp:ExactlyOne>
<wsp:All>
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<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:Lax/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
</wsp:Policy>
</sp:TransportBinding>
<sp:SignedSupportingTokens xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:UsernameToken
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
<sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy/>
</sp:Wss10>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:portType name="ISMSXMLWebService">
<wsdl:operation name="G4TLogin">
<wsdl:input wsaw:Action="http://tempuri.org/ISMSXMLWebService/G4TLogin"
message="tns:ISMSXMLWebService_G4TLogin_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/ISMSXMLWebService/G4TLoginResponse"
message="tns:ISMSXMLWebService_G4TLogin_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WSHttpBinding_ISMSXMLWebService" type="tns:ISMSXMLWebService">
<wsp:PolicyReference URI="#WSHttpBinding_ISMSXMLWebService_policy"/>
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="G4TLogin">
<soap12:operation soapAction="http://tempuri.org/ISMSXMLWebService/G4TLogin" style="document"/>
<wsdl:input>
<wsp:PolicyReference URI="#WSHttpBinding_ISMSXMLWebService_G4TLogin_Input_policy"/>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<wsp:PolicyReference URI="#WSHttpBinding_ISMSXMLWebService_G4TLogin_output_policy"/>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="BasicHttpBinding_ISMSXMLWebService" type="tns:ISMSXMLWebService">
<wsp:PolicyReference URI="#BasicHttpBinding_ISMSXMLWebService_policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="G4TLogin">
<soap:operation soapAction="http://tempuri.org/ISMSXMLWebService/G4TLogin" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="SMSXMLWebService">
<wsdl:port name="WSHttpBinding_ISMSXMLWebService" binding="tns:WSHttpBinding_ISMSXMLWebService">
<soap12:address location="http://address.com/smsXMLWebService/SMSXMLWebService.svc"/>
<wsa10:EndpointReference>
<wsa10:Address>http://address.com/smsXMLWebService/SMSXMLWebService.svc
</wsa10:Address>
<Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<X509Data>
<X509Certificate>
cert
</X509Certificate>
</X509Data>
</KeyInfo>
</Identity>
</wsa10:EndpointReference>
</wsdl:port>
<wsdl:port name="BasicHttpBinding_ISMSXMLWebService" binding="tns:BasicHttpBinding_ISMSXMLWebService">
<soap:address location="https://desktop-hlm3poi/smsXMLWebService/SMSXMLWebService.svc/basicHttp"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Комментарии:
1. Ваш файл WSDL использует SOAP1.2, поэтому вам нужно изменить soap_version на SOAP_1_2. Ошибки плохого шлюза могут быть вызваны внутренними ошибками на сервере. Пожалуйста, проверьте, работает ли сервер нормально.
2. Сервер @DingPeng работает нормально.
3. Может ли приложение c # успешно вызвать его?
4. @DingPeng не знаю. Мы реализуем только клиентскую часть PHP.
5. Я подозреваю, что это может быть проблема с сервером WCF.