开发者

Consume php webservice in .net (VS2010)

开发者 https://www.devze.com 2023-03-06 22:51 出处:网络
I have a webservice, written in PHP, which I want to consume in a .NET application. I have used the standard SoapServer implementation of PHP, with a selfwritten WSDL file. Here is the WSDL file:

I have a webservice, written in PHP, which I want to consume in a .NET application. I have used the standard SoapServer implementation of PHP, with a selfwritten WSDL file. Here is the WSDL file:

<?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/"/>
            </in开发者_运维知识库put>
            <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>

Along with that I have the following webservice implementation:

<?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();
?>

If I communicate with this service using SoapUI, it works like a charm, methods get called and return what they are supposed to.

Now I am trying to consume the same webservice in a .NET application, but for some reason, it does not generate the proxy class and I am not able to use it.

Does anyone has had this problem before or knows how to deal with it?


that WSDL looks to be rpc/encoding rather than document/literal. These don't behave as expected with the DataContractSerialiser.

you should try svcutil to generate the .cs from there. more options.

if you can host the php service online and point me to a wsdl, i'd be happy to try.

0

精彩评论

暂无评论...
验证码 换一张
取 消