在 .net 中使用 php webservice (VS2010)

本文关键字:webservice VS2010 php net | 更新日期: 2023-09-27 17:57:03

我有一个用PHP编写的Web服务,我想在.NET应用程序中使用它。我使用了PHP的标准SoapServer实现,以及一个自己编写的WSDL文件。下面是 WSDL 文件:

<?xml version="1.0"?>
<definitions name="Calculator"
             targetNamespace="urn:Calculator"
             xmlns:tns="urn:Calculator"
             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/">
    <!-- Definition of types used in the WSDL http://localhost/services/wsdl/CalculatorService.wsdl -->
    <types>
        <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNameSpace="urn:Calculator">
            <xsd:element name="Reflect" type="xsd:string" />
            <xsd:element name="ReflectResponse" type="xsd:string" />
            <xsd:element name="GimmePiResponse" type="xsd:float" />
        </xsd:schema>
    </types>
    <!-- Abstract definition of the data being transmitted in -->
    <message name="CalculatorService_Reflect_InputMessage">
        <part name="stringToEcho" element="tns:Reflect" />
    </message>
    <!-- Abstract definition of the data being transmitted out -->
    <message name="CalculatorService_Reflect_OutputMessage">
        <part name="return" element="tns:ReflectResponse" />
    </message>
    <message name="CalculatorService_GimmePi_OutputMessage">
        <part name="return" element="tns:GimmePiResponse" />
    </message>
    <!-- A set of abstract operations referring to input and output messages -->
    <portType name="CalculatorServiceOperations">
        <operation name="Reflect">
            <input message="tns:CalculatorService_Reflect_InputMessage" />
            <output message="tns:CalculatorService_Reflect_OutputMessage" />
        </operation>
        <operation name="GimmePi">
            <output message="tns:CalculatorService_GimmePi_OutputMessage" />
        </operation>
    </portType>
    <!-- Concrete protocol and data format specifications -->
    <binding name="HttpBinding_CalculatorService" type="tns:CalculatorServiceOperations">
        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="Reflect">
            <soap:operation soapAction="urn:ReflectAction"/>
            <input>
                <soap:body use="encoded" namespace="urn:Calculator" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </input>
            <output>
                <soap:body use="encoded" namespace="urn:Calculator" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
        <operation name="GimmePi">
            <soap:operation soapAction="urn:GimmePiAction"/>
            <output>
                <soap:body use="encoded" namespace="urn:Calculator" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
            </output>
        </operation>
    </binding>
    <!-- Specifies location and bindings for a service -->
    <service name="CalculatorService">
        <port name="CalculatorServiceOperations" binding="tns:HttpBinding_CalculatorService">
            <soap:address location="http://localhost/services/CalculatorService.php" />
        </port>
    </service>
</definitions>

除此之外,我还有以下 Web 服务实现:

<?php
if (!extension_loaded("soap"))
{
    dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("CalculatorService.wsdl");
function GimmePi()
{
    return 3.14;
}
function Reflect($stringToEcho)
{
    return $stringToEcho;
}
$server->AddFunction("GimmePi");
$server->AddFunction("Reflect");
$server->handle();
?>

如果我使用 SoapUI 与此服务通信,它就像一个魅力,方法被调用并返回它们应该返回的内容。

现在我正在尝试在 .NET 应用程序中使用相同的 Web 服务,但由于某种原因,它不会生成代理类,我无法使用它。

有没有人以前遇到过这个问题或知道如何处理它?

在 .net 中使用 php webservice (VS2010)

WSDL看起来是rpc/encoding而不是document/literal。这些行为与DataContractSerialiser的预期不同。

您应该尝试svcutil从那里生成.cs。 更多选项。

如果您可以在线托管php服务并指出我wsdl,我很乐意尝试。