[英]Consume php webservice in .net (VS2010)
I have a webservice, written in PHP, which I want to consume in a .NET application. 我有一个用PHP编写的Web服务,我想在.NET应用程序中使用它。 I have used the standard SoapServer implementation of PHP, with a selfwritten WSDL file.
我使用了标准的SoapServer PHP实现和一个自写的WSDL文件。 Here is the WSDL file:
这是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>
Along with that I have the following webservice implementation: 除此之外,我还具有以下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();
?>
If I communicate with this service using SoapUI, it works like a charm, methods get called and return what they are supposed to. 如果我使用SoapUI与该服务进行通信,则它的工作原理就像一种魅力,方法被调用并返回其应有的功能。
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. 现在,我试图在.NET应用程序中使用相同的Web服务,但是由于某种原因,它不会生成代理类,因此我无法使用它。
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
. WSDL看起来是
rpc/encoding
而不是document/literal
。 These don't behave as expected with the DataContractSerialiser
. 这些与
DataContractSerialiser
行为不符。
you should try svcutil
to generate the .cs from there. 您应该尝试
svcutil
从那里生成.cs。 more options. 更多选择。
if you can host the php
service online and point me to a wsdl
, i'd be happy to try. 如果您可以在线托管
php
服务并将我指向wsdl
,我将很乐意尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.