问题
I am using the WSDL document automatically generated by Visual Studio 2010 (ie. from the "HelloWorld" application that is created when you create a new web service application in Visual Studio.) But I am needing to develop the web service in PHP, so I am using this WSDL document with PHP SoapServer. I will copy the WSDL document here:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/"
xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="HelloWorld">
<s:complexType />
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
<wsdl:portType name="Service1Soap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="Service1Soap" type="tns:Service1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="Service1Soap12" type="tns:Service1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Service1">
<wsdl:port name="Service1Soap" binding="tns:Service1Soap">
<soap:address location="helloworld_server.php" />
</wsdl:port>
<wsdl:port name="Service1Soap12" binding="tns:Service1Soap12">
<soap12:address location="helloworld_server.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
My PHP SoapServer code looks like this:
function HelloWorld()
{
return "Hello world!";
}
$server = new SoapServer( 'helloworld.wsdl' );
$server->addFunction('HelloWorld');
try {
$server->handle();
}
catch (Exception $e) {
$server->fault('Sender', $e->getMessage());
}
When I try call this soap service with a .Net client, I am getting an empty string returned. Does anyone know what is going wrong with this simple example?
UPDATE:
This specifically seems to be a problem with communicating with a .Net client from the PHP server. I have tested with a PHP client and I get the message returned by the server in the PHP client. But for some reason the .Net client gets an empty string returned. For the .Net client, I created a simple WinForms application, added a web reference to the php soap server. The web reference gets added correctly and shows the API. I put one button on the form with the following click handle:
private void button1_Click(object sender, EventArgs e)
{
WebReference.Service1 srv = new WebReference.Service1();
string result = srv.HelloWorld();
MessageBox.Show(result);
}
来源:https://stackoverflow.com/questions/8188828/string-values-returned-by-php-soapserver-not-received-by-net-client