2013-06-27 96 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 –