Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用WCF调用PHP-SOAP服务_C#_Php_Wcf_Soap_Wsdl - Fatal编程技术网

C# 使用WCF调用PHP-SOAP服务

C# 使用WCF调用PHP-SOAP服务,c#,php,wcf,soap,wsdl,C#,Php,Wcf,Soap,Wsdl,我必须开发一个.NET API来运行php soap服务,但我只有一个指定服务属性的WSDL文件 当我尝试在Visual Studio中使用WSDL文件进行服务引用时,它不起作用,会出现一个错误: “响应消息的内容类型text/plain不匹配 绑定的内容类型(application/soap+xml;charset=utf-8)。 如果使用自定义编码器,请确保iContentTypeSupported 方法已正确实现。” 当我在Visual Studio中打开WSDL时,intellisens

我必须开发一个.NET API来运行php soap服务,但我只有一个指定服务属性的WSDL文件

当我尝试在Visual Studio中使用WSDL文件进行服务引用时,它不起作用,会出现一个错误

“响应消息的内容类型text/plain不匹配 绑定的内容类型(application/soap+xml;charset=utf-8)。 如果使用自定义编码器,请确保iContentTypeSupported 方法已正确实现。”

当我在Visual Studio中打开WSDL时,intellisense在中遇到了一个问题,它说:“未定义命名空间前缀“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>


谢谢

这个WSDL确实无效,因为没有定义xs前缀。要修复此问题,请添加以下定义:

xmlns:xs="http://www.w3.org/2001/XMLSchema"
在第一个标签的某个地方,靠近类似的定义

regardeless我总是建议首先获得一个工作soap示例(可能来自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>


谢谢,现在我可以添加服务参考。但是我不能创建任何变量来使用它,这样使用php soap服务和wcf是否可能?我的意思是这里没有任何端点定义。我现在看到这个服务是rpc/编码的。我建议使用.net 2客户端而不是wcf,例如“添加web引用”而不是“添加服务引用”这里是如何添加web服务引用好的,我这样做了,我将web服务称为“ProtopmailWebservice”,但我仍然无法创建任何具有该类型的变量(正确添加了命名空间)