2013-06-27 98 views
0

我必須開發一個.NET API到工作PHP SOAP服務,但我只有一個WSDL文件,指定服務屬性。使用WCF調用PHP SOAP服務

當我試圖讓與WSDL文件,它不工作,在Visual Studio中的服務引用,一個錯誤發生:

「響應消息的內容類型text/plain的不匹配 內容類型的結合(應用/肥皂+ xml的;字符集= UTF-8)。 如果使用定製的編碼器,可以肯定的是,IsContentTypeSupported 方法被適當地實現「

當我打開。在Visual Studio中的WSDL,intellisense有< xs的問題:序列號>在<類型>,它表示:「名稱空間前綴'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> 

感謝

回答

1

這是事實,這是WSDL由於未定義xs前綴,因此無效。要修復它,請添加此定義:

xmlns:xs="http://www.w3.org/2001/XMLSchema" 

某處的第一個標籤附近有類似的定義。

regardeless我總是建議先得到一個示例工作肥皂(也許從一個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> 
+0

謝謝,現在我可以添加服務參考。但我不能創建任何變量來使用它,甚至有可能使用wcf這種方式使用php肥皂服務?我的意思是這裏沒有任何端點定義。 –

+0

我現在看到這個服務是rpc /編碼的。我建議使用.net 2客戶端,而不是wcf,例如「添加Web引用」而不是「添加服務引用」 –

+0

這裏是如何添加Web服務引用http://webservices20.blogspot.co.il/2008/10/interoperability-gotcha-visual-studio.html –