簡體   English   中英

編輯wsdl以使用asp.net中的php Web服務

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

我在asp.net Web api項目中無法使用php Web服務(無法修改)。 我嘗試使用“添加服務參考”和“添加網絡參考”,但仍然無法正常工作。 我正在嘗試找到一種解決方案,向我解釋如何編輯或重建wsdl文件(我將其保存在本地),以便可以使用它來使用服務。 我發現了另一個類似的線程,但是沒有可以幫助我的解決方案。 我的問題與.NET 2.0的問題非常相似,但我使用的是.NET 4.5:

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

這是我的錯誤消息:

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>

非常感謝,任何建議我都感激。

好吧,我解決了! (我和之前問過這個問題的cxnv是同一個人,但是根據stackoverflow標准來看,我似乎是一個非常糟糕的貢獻者,我當然不知道為什么,但是...這還是我的答案,我只是沒有希望看到它尚未解決)

幸運的是,我發現該服務未使用WSDataArray complexType,因此我在wsdl中將其刪除,並將修改后的wsdl導入到我的asp.net項目中(如果使用該WSDataArray,我仍然不知道該怎么辦)。 但是后來我遇到了一個問題,因為響應是用iso-8859-1編碼的,所以我在這篇有用的文章上將其修復了,瞧瞧!

該課程始終避免在php中公開Web服務! 本文的作者對此進行了很好的解釋:

“ PHP是一種弱類型的語言(...),因此無法生成WSDL文件進行反射。這對於PHP作為Web服務平台的適用性是一個嚴重的限制, 因為它阻止了PHP Web服務與編寫的客戶端之間的輕松互操作性用其他語言。

在這種情況下,我無法訪問服務來源,但我希望我的合作伙伴將來會考慮此建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM