我必须为正在运行的 php soap服务开发 .NET API ,但我只有 WSDL文件,它指定了服务属性。
当我尝试使用WSDL文件在Visual Studio中创建服务引用时,它不起作用,会出现错误:
“响应消息的内容类型text / plain不匹配 绑定的内容类型(application / soap + xml; charset = utf-8)。 如果使用自定义编码器,请确保IsContentTypeSupported 方法正确实施。 “
当我在Visual Studio中打开WSDL时,intellisense遇到了< xs:sequence>的问题。在< types>中,它说:“命名空间前缀'xs'未定义” - 也许这里有问题,但我不会说WSDL ....
这是WSDL文件:
<?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>
由于
答案 0 :(得分:1)
由于未定义xs前缀,因此该WSDL无效。要修复它,请添加以下定义:
xmlns:xs="http://www.w3.org/2001/XMLSchema"
靠近相似定义的第一个标签上的某处。
无条件我总是建议首先获得一个样本工作肥皂(可能来自php客户端或供应商),然后使用C#。 编辑:这个wsdl还有一些问题 - 名称空间定义tns与模式目标名称空间不同,所以我任意选择了一个,并且返回类型引用了一个未知类型,因此我将其更改为字符串。试试这个:<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>