dongtan1009 2014-12-30 23:37
浏览 37

编辑wsdl以在asp.net中使用php web服务

I'm having troubles to consume a php web service (which I can't modify) in my asp.net web api project. I tried to use "Add service reference" and "Add web reference", but still it's not working. I'm trying to find a solution that explain me how to edit or reconstruct the wsdl file (which I saved locally) so I can use it to consume the services. I've found another similar threads but without a solution that can help me. My problem is very similar to this one with .NET 2.0 but I'm using .NET 4.5:

https://social.msdn.microsoft.com/Forums/en-US/4d5b1e36-21b9-454b-b155-3d14bba49b82/how-to-consume-a-php-web-service-from-net-when-wsdlexe-cant-read-the-wsdl?referrer=http://social.msdn.microsoft.com/Forums/en-US/4d5b1e36-21b9-454b-b155-3d14bba49b82/how-to-consume-a-php-web-service-from-net-when-wsdlexe-cant-read-the-wsdl?forum=asmxandxml

Here is my errors message:

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.

The lines 28 to 30 are:

<xsd:element name="WSData" type="tns:WSData" datos="WSData"/>
  <xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="tns:WSData[]"/>
</xsd:restriction>

Here is my entire wsdl file:

<?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>

Thank you so much, I appreciate any suggestion.

  • 写回答

1条回答 默认 最新

  • douduikai0562 2014-12-31 20:57
    关注

    Well, I solved! (I'm the same cxnv who asked this before but it seems I'm a very bad contributor according to the stackoverflow standards, I certainly don't know why, however... here is my answer anyway, I just didn't want to see it unsolved)

    Fortunately, I found that The service wasn't using the WSDataArray complexType, so I deleted it in the wsdl and imported the modified the wsdl to my asp.net project (I still don't know what should I do if that WSDataArray were used). But then I was facing a problem because of the response was encoded with iso-8859-1, so I fixed it following this useful article, and voilà!!

    The lesson is always avoid exposing web services in php!! The author of this article explain it very well:

    "PHP is a weakly typed language (...), therefore reflection to generate WSDL files is impossible. This is a serious limitation for the applicability of PHP as a web services platform as it prevents PHP web services from having easy interoperability with clients written in other languages."

    In this case I hadn't access to the service sources, but I hope my partner take into account this advice in the future.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料