.Net 客户端未收到 PHP SoapServer 返回的字符串值

发布于 2024-12-17 07:06:00 字数 4096 浏览 0 评论 0原文

我正在使用 Visual Studio 2010 自动生成的 WSDL 文档(即,来自在 Visual Studio 中创建新的 Web 服务应用程序时创建的“HelloWorld”应用程序)。但是我需要在 PHP 中开发 Web 服务,所以我正在将这个 WSDL 文档与 PHP SoapServer 一起使用。我将在此处复制 WSDL 文档:

<?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>

我的 PHP SoapServer 代码如下所示:

function HelloWorld()
{
   return "Hello world!";
}

$server = new SoapServer( 'helloworld.wsdl' );
$server->addFunction('HelloWorld');
try {
   $server->handle();
}
catch (Exception $e) {
   $server->fault('Sender', $e->getMessage());
}

当我尝试使用 .Net 客户端调用此肥皂服务时,我收到返回的空字符串。有谁知道这个简单的例子出了什么问题?

更新:

这似乎是从 PHP 服务器与 .Net 客户端通信时出现的问题。我已经用 PHP 客户端进行了测试,我在 PHP 客户端中获取了服务器返回的消息。但由于某种原因,.Net 客户端返回了一个空字符串。对于 .Net 客户端,我创建了一个简单的 WinForms 应用程序,添加了对 php Soap 服务器的 Web 引用。 Web 参考已正确添加并显示 API。我在表单上放置了一个带有以下单击句柄的按钮:

private void button1_Click(object sender, EventArgs e)
{
    WebReference.Service1 srv = new WebReference.Service1();
    string result = srv.HelloWorld();
    MessageBox.Show(result);
}

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文