Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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# 在.net(VS2010)中使用php Web服务_C#_Php_Visual Studio 2010 - Fatal编程技术网

C# 在.net(VS2010)中使用php Web服务

C# 在.net(VS2010)中使用php Web服务,c#,php,visual-studio-2010,C#,Php,Visual Studio 2010,我有一个用PHP编写的Web服务,我想在.NET应用程序中使用它。我使用了PHP的标准SoapServer实现,以及一个自写的WSDL文件。以下是WSDL文件: <?xml version="1.0"?> <definitions name="Calculator" targetNamespace="urn:Calculator" xmlns:tns="urn:Calculator" xmlns:xs

我有一个用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应用程序中使用相同的webservice,但由于某些原因,它不会生成代理类,因此我无法使用它


是否有人曾经遇到过这个问题,或者知道如何处理它?

WSDL看起来是
rpc/encoding
而不是
document/literal
。对于
DataContractSerialiser
,这些行为与预期不符

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


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

该wsdl看起来是
rpc/encoding
,而不是
文档/文字
。对于
DataContractSerialiser
,这些行为与预期不符

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


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

我已经在线获得了wsdl文件,但该服务还不能工作;必须有一些与php设置要做的事情。检查以下URL:详细信息:运行WSDL导入扩展时引发异常:System.ServiceModel.Description.XmlSerializerMessageCompactImporterError:找不到目标命名空间为“urn:Calculator”的架构。XPath至错误源://WSDL:definitions[@targetNamespace='urn:Calculator']/WSDL:portType[@name='CalculatorServiceOperations']好的,第一个错误是使用targetNamespace urn:Calculator中的,这不应该是路径吗?像那样?根据所有的例子…不是。但我发现了一个更令人不安的事实。我的提供商没有为PHP启用SOAP扩展!这使我的整个研究无效。我可能会去一个支持.net的提供商那里,然后我可以进行WCF…感谢您的支持,尽管我已将wsdl文件联机,但该服务尚未运行;必须对php设置进行一些处理。请检查以下URL:详细信息:运行wsdl导入扩展时引发异常:System.ServiceModel.Description.XmlSerializerMessageCompactImporterError:Schema with tar找不到获取命名空间“urn:Calculator”。XPath错误源://wsdl:definitions[@targetNamespace='urn:Calculator']//wsdl:portType[@name='CalculatorServiceOperations']好的,第一个错误是使用targetNamespace urn:Calculator中的,这不应该是路径吗?像那样?根据所有的例子…不是。但我发现了一个更令人不安的事实。我的提供商没有为PHP启用SOAP扩展!这使我的整个研究无效。我可能会去一个支持.net的提供商那里,然后我可以做WCF…谢谢你的支持