Reputation: 23
I've been trying for a long time to connect to a web service like this:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" name="Service1" targetNamespace="http://tempuri.org/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<xs:import namespace="http://schemas.datacontract.org/2004/07/WcfService1"/>
<xs:element name="JsonWebMessage">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="message" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="JsonWebMessageResponse">
<xs:complexType>
<xs:sequence>
<xs:element xmlns:q1="http://schemas.datacontract.org/2004/07/WcfService1" minOccurs="0" name="JsonWebMessageResult" nillable="true" type="q1:ServiceResult"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.microsoft.com/2003/10/Serialization/" 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>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.datacontract.org/2004/07/WcfService1" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/WcfService1">
<xs:complexType name="ServiceResult">
<xs:sequence>
<xs:element minOccurs="0" name="IsValid" type="xs:boolean"/>
<xs:element minOccurs="0" name="ReturnJson" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="ServiceResult" nillable="true" type="tns:ServiceResult"/>
</xs:schema>
</wsdl:types>
<wsdl:message name="IService1_JsonWebMessage_InputMessage">
<wsdl:part name="parameters" element="tns:JsonWebMessage"/>
</wsdl:message>
<wsdl:message name="IService1_JsonWebMessage_OutputMessage">
<wsdl:part name="parameters" element="tns:JsonWebMessageResponse"/>
</wsdl:message>
<wsdl:portType name="IService1">
<wsdl:operation name="JsonWebMessage">
<wsdl:input wsaw:Action="http://tempuri.org/IService1/JsonWebMessage" message="tns:IService1_JsonWebMessage_InputMessage"/>
<wsdl:output wsaw:Action="http://tempuri.org/IService1/JsonWebMessageResponse" message="tns:IService1_JsonWebMessage_OutputMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:service name="Service1"/>
</wsdl:definitions>
According to the wsdl xml document, this service has an operation named JsonWebMessage, which accepts a string as input (which is stringified JSON). I use this PHP code to acces this service:
<?php
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) )
{
$message = $_GET['message'];
$wcf = new SoapClient('URL_HERE/Service1.svc?singleWsdl');
$sonuc = $wcf->JsonWebMessage(array("message" => $message));
echo $sonuc;
}
?>
But whatever I do I can't connect to the service. I tried using 'URL_HERE/Service1.svc/ws' as address to no avail. After a while of pending request the response is 500 internal server error. The URL_HERE includes the port number 8100 like this: URL_HERE:8100/Service1.svc. The resulting error messages from php when I turn on error reporting is:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'URL_HERE/Service1.svc?singleWsdl' : failed to load external entity "http://URL_HERE/Service1.svc?singleWsdl" in SOURCE_URL/formtercuman.php:10Stack trace:#0 SOURCE_URL/formtercuman.php(10): SoapClient->SoapClient('http://....')#1 {main} thrown in SOURCE_URL/formtercuman.php on line 10
Upvotes: 1
Views: 4176
Reputation: 23
The issue is resolved. The problem was related to the firewall settings of windows IIS server. We don't know exactly what was wrong but we disabled the firewall altogether and decided to use a fortigate firewall machine which has zero problems with connections. Thanks.
Upvotes: 1
Reputation: 331
Sever-Client connectivity is RESOLVED. I'm past the Fatal error you posted earlier.
After connectivity it shows that it has VERSION error.
Error showing up "[faultstring] => Wrong Version, [faultcode] => VersionMismatch". Your SoapClient line:
$wcf = new SoapClient('URL_HERE/Service1.svc?singleWsdl');
Should be as follows (taken from http://www.php.net/manual/en/soapclient.soapclient.php ):
$wcf = new SoapClient(null, array('location' => "http://localhost/Service1.svc",
'soap_version' => SOAP_1_2,
'uri' => "http://test-uri/",
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL));
If I was you, I'd use try-catch way to get things done, like:
try{
$wcf = new SoapClient(null, array('location' => "http://localhost/Service1.svc",
'soap_version' => SOAP_1_2,
'uri' => "http://test-uri/",
'style' => SOAP_DOCUMENT,
'use' => SOAP_LITERAL));
$sonuc = $wcf->JsonWebMessage(array("message" => $message));
echo $sonuc;
} catch (Exception $e){
print('<pre>');
print_r($e);
print('</pre>');
}
You can look up the correct version of the WSDL and set it the same way in the options.
Upvotes: 0