Reputation: 721
I have to develop a .NET API to a working php soap service, but I only have a WSDL file, that specifies the service attributes.
When I try to make a Service Reference in Visual Studio with the WSDL file it doesn't work, an error occurs:
"The content type text/plain of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. "
When I open the WSDL in Visual Studio, intellisense has a problem with <xs:sequence> in <types>, it says: "Namespace prefix 'xs' is not defined" - maybe there's something wrong here, but I don't speak WSDL....
Here is the WSDL file:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="ProtopmailApiWorld"
targetNamespace="urn:ProtopmailApiWorld"
xmlns:tns="urn:ProtopmailApiWorld"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:API">
<xsd:complexType name="arrayOfStrings">
<xs:sequence>
<xs:element name="TheStringValue" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xsd:complexType>
<xsd:element name="outResponse" type="xsd:string" />
</xsd:schema>
</types>
<message name="ApiSoap">
<part name="params" type="tns:arrayOfStrings" />
</message>
<message name="ApiSoapResponse">
<part name="return" type="tns:outResponse" />
</message>
<portType name="APIPort">
<operation name="ApiSoap">
<input message="tns:ApiSoap" />
<output message="tns:ApiSoapResponse" />
</operation>
</portType>
<binding name="APIBinding" type="tns:APIPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="ApiSoap">
<soap:operation soapAction="urn:ApiSoapAction" />
<input>
<soap:body use="encoded" namespace="urn:API" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:API" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="ApiSoapService">
<port name="APIPort" binding="tns:APIBinding">
<soap:address location="https://website/api/soap.php" />
</port>
</service>
Thanks
Upvotes: 0
Views: 1132
Reputation: 24396
It is true that this WSDL is not valid since the xs prefix is not defined. To fix it add this definition:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
somewhere on the first tag near the similar definitions.
regardeless I always recommend to first get a sample working soap (maybe from a php client, or the vendor) and then use C#.
EDIT: There were a few more problems with this wsdl - the namespace definition tns was different than the schema target namespace, so I arbitrarly chose one, and also the return type referes to an unknown type, so I changes it to string. try this:
<definitions name="ProtopmailApiWorld"
targetNamespace="urn:ProtopmailApiWorld"
xmlns:tns="urn:ProtopmailApiWorld"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ProtopmailApiWorld">
<xsd:complexType name="arrayOfStrings">
<xs:sequence>
<xs:element name="TheStringValue" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xsd:complexType>
<xsd:element name="outResponse" type="xsd:string" />
</xsd:schema>
</types>
<message name="ApiSoap">
<part name="params" type="tns:arrayOfStrings" />
</message>
<message name="ApiSoapResponse">
<part name="return" type="xsd:string" />
</message>
<portType name="APIPort">
<operation name="ApiSoap">
<input message="tns:ApiSoap" />
<output message="tns:ApiSoapResponse" />
</operation>
</portType>
<binding name="APIBinding" type="tns:APIPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="ApiSoap">
<soap:operation soapAction="urn:ApiSoapAction" />
<input>
<soap:body use="encoded" namespace="urn:API" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:API" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="ApiSoapService">
<port name="APIPort" binding="tns:APIBinding">
<soap:address location="https://website/api/soap.php" />
</port>
</service>
</definitions>
Upvotes: 1