简体   繁体   English

编辑wsdl以使用asp.net中的php Web服务

[英]Edit wsdl to consume php web service in asp.net

I'm having troubles to consume a php web service (which I can't modify) in my asp.net web api project. 我在asp.net Web api项目中无法使用php Web服务(无法修改)。 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. 我正在尝试找到一种解决方案,向我解释如何编辑或重建wsdl文件(我将其保存在本地),以便可以使用它来使用服务。 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: 我的问题与.NET 2.0的问题非常相似,但我使用的是.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 https://social.msdn.microsoft.com/Forums/zh-CN/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-当wsdlexe无法读取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: 第28至30行是:

<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: 这是我的整个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>

Thank you so much, I appreciate any suggestion. 非常感谢,任何建议我都感激。

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) (我和之前问过这个问题的cxnv是同一个人,但是根据stackoverflow标准来看,我似乎是一个非常糟糕的贡献者,我当然不知道为什么,但是...这还是我的答案,我只是没有希望看到它尚未解决)

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). 幸运的是,我发现该服务未使用WSDataArray complexType,因此我在wsdl中将其删除,并将修改后的wsdl导入到我的asp.net项目中(如果使用该WSDataArray,我仍然不知道该怎么办)。 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à!! 但是后来我遇到了一个问题,因为响应是用iso-8859-1编码的,所以我在这篇有用的文章上将其修复了,瞧瞧!

The lesson is always avoid exposing web services in php!! 该课程始终避免在php中公开Web服务! 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. " “ PHP是一种弱类型的语言(...),因此无法生成WSDL文件进行反射。这对于PHP作为Web服务平台的适用性是一个严重的限制, 因为它阻止了PHP Web服务与编写的客户端之间的轻松互操作性用其他语言。

In this case I hadn't access to the service sources, but I hope my partner take into account this advice in the future. 在这种情况下,我无法访问服务来源,但我希望我的合作伙伴将来会考虑此建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM