2

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 クライアントでこの SOAP サービスを呼び出そうとすると、空の文字列が返されます。この単純な例で何がうまくいかないのか誰にもわかりませんか?

アップデート:

これは特に、PHP サーバーから .Net クライアントとの通信に問題があるようです。PHP クライアントでテストしたところ、PHP クライアントでサーバーからメッセージが返されました。しかし、何らかの理由で .Net クライアントに空の文字列が返されます。.Net クライアント用に、簡単な WinForms アプリケーションを作成し、PHP SOAP サーバーへの Web 参照を追加しました。Web 参照が正しく追加され、API が表示されます。次のクリック ハンドルを使用して、フォームにボタンを 1 つ配置します。

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

0 に答える 0