我有一个用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>
除此之外,我还有以下webservice实现:
<?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服务,但由于某种原因,它不会生成代理类,我无法使用它。
有没有人之前遇到过这个问题或者知道如何处理它?</ p>
答案 0 :(得分:1)
WSDL看起来是rpc/encoding
而不是document/literal
。这些行为与DataContractSerialiser
不符合预期。
你应该尝试svcutil
从那里生成.cs。更多选择。
如果您可以在线托管php
服务并指向wsdl
,我很乐意尝试。