我在asp.net web api项目中使用php web服务(我无法修改)时遇到麻烦。我尝试使用“添加服务引用”和“添加Web引用”,但它仍然无法正常工作。我正在尝试找到一个解释我如何编辑或重建wsdl文件(我在本地保存)的解决方案,以便我可以使用它来使用服务。我找到了另一个类似的线程,但没有可以帮助我的解决方案。我的问题与.NET 2.0非常类似,但我使用的是.NET 4.5:
这是我的错误消息:
The document at the url file:xxx was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'The root element of a W3C XML Schema should be <schema> and its namespace should be 'http://www.w3.org/2001/XMLSchema'.'.
- Report from 'DISCO Document' is 'Discovery document at the URL file:xxx could not be found.'.
- The document format is not recognized.
- Report from 'WSDL Document' is 'There is an error in XML document (29, 6).'.
- The element was not expected in this context: <xsd:element xmlns:xsd='http://www.w3.org/2001/XMLSchema'>..</xsd:element>. Expected elements: http://www.w3.org/2001/XMLSchema:annotation, http://www.w3.org/2001/XMLSchema:choice, http://www.w3.org/2001/XMLSchema:group, http://www.w3.org/2001/XMLSchema:all, http://www.w3.org/2001/XMLSchema:sequence, http://www.w3.org/2001/XMLSchema:attributeGroup, http://www.w3.org/2001/XMLSchema:attribute, http://www.w3.org/2001/XMLSchema:anyAttribute.
第28至30行是:
<xsd:element name="WSData" type="tns:WSData" datos="WSData"/>
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:WSData[]"/>
</xsd:restriction>
这是我的整个wsdl文件:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php">
<wsdl:types>
<xsd:schema targetNamespace="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php"
>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<xsd:complexType name="WSDataIN">
<xsd:all>
<xsd:element name="user" type="xsd:string" datos="user"/>
<xsd:element name="password" type="xsd:string" datos="password"/>
<xsd:element name="message" type="xsd:string" datos="message"/>
<xsd:element name="datetime" type="xsd:string" datos="datetime"/>
<xsd:element name="messageid" type="xsd:string" datos="messageid"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="WSData">
<xsd:all>
<xsd:element name="codigores" type="xsd:string" datos="codigores"/>
<xsd:element name="descrres" type="xsd:string" datos="descrres"/>
</xsd:all>
</xsd:complexType>
<xsd:complexType name="WSDataArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:element name="WSData" type="tns:WSData" datos="WSData"/>
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:WSData[]"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="EnviaSMSRequest">
<part name="datos" type="tns:WSDataIN" /> <wsdl:/message>
<wsdl:message name="EnviaSMSResponse">
<part name="return" type="tns:WSData" /> <wsdl:/message>
<wsdl:portType name="WSEnvioSMSPortType">
<operation name="EnviaSMS">
<documentation>Envia SMS a clientes </documentation>
<input message="tns:EnviaSMSRequest"/>
<output message="tns:EnviaSMSResponse"/>
</operation>
</wsdl:portType>
<wsdl:binding name="WSEnvioSMSBinding" type="tns:WSEnvioSMSPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="EnviaSMS">
<soap:operation soapAction="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php?wsdl#EnviaSMS" style="rpc"/>
<input> <soap:body use="encoded" namespace="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php?wsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input>
<output> <soap:body use="encoded" namespace="https://oneurl.tv/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php?wsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output>
</operation>
</wsdl:binding>
<wsdl:service name="WSEnvioSMS">
<port name="WSEnvioSMSPort" binding="tns:WSEnvioSMSBinding">
<soap:address location="https://oneurl.tv:443/urlexists/1045_APPmobileApp/wsdl/WSDLEnvio.php"/>
</port>
</wsdl:service>
</wsdl:definitions>
非常感谢,我感谢任何建议。
答案 0 :(得分:0)
好吧,我解决了! (我和之前问过这个问题的cxnv相同,但根据stackoverflow标准,我似乎是一个非常糟糕的贡献者,我当然不知道为什么,但是......无论如何......这里是我的答案,我只是没有希望看到它未解决)
幸运的是,我发现该服务没有使用WSDataArray complexType,所以我在wsdl中将其删除并将修改后的wsdl导入我的asp.net项目(我仍然不知道该怎么办?使用了WSDataArray)。但后来我遇到了一个问题,因为响应是用iso-8859-1编码的,所以我在this useful article之后修复了它,并且vo !!
总是避免在php中暴露Web服务! this article的作者解释得非常好:
“PHP是一种弱类型语言(...),因此生成WSDL文件的反射是不可能的。这是PHP作为Web服务平台的适用性的严重限制,因为它阻止了PHP Web服务与使用其他语言编写的客户轻松互操作。“
在这种情况下,我无法访问服务来源,但我希望我的合作伙伴将来会考虑这个建议。