2015-01-18 2 views
0

У меня есть простой soperver сервера php, и я также создал wsdl-файл для него. Я могу использовать его в php, но я хочу его использовать в .net winform too.I искали но ни одна из предложенных статей не была полезной. не могли бы вы мне помочь, пожалуйста? вот мой SoapServer и название страницы testserver.php:может, t потребляющий php soapserver в C# winform

class TestClass 
{ 
    function hello($someone) 
    { 
     return "Hello " . $someone . " Welcome To Wsdl World!"; 
    } 
    function SumData($a,$b) 
    { 
     //return "this is test"; 
     return $a+$b; 
    } 
} 
    ini_set("soap.wsdl_cache_enabled", "0"); 
    $server = new SoapServer("http://localhost/webservices/simple/test1.wsdl",array('soap_version' => SOAP_1_2)); 
    $server->setClass('TestClass'); 
    $server->handle(); 
?> 

и вот мой файл WSDL и имя файла test1.wsdl:

<?xml version="1.0"?> 
<wsdl:definitions name="MyDefinition" 
        targetNamespace="urn:myTargetNamespace" 
        xmlns:tns="urn:myTns" 
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
        xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
        xmlns="http://schemas.xmlsoap.org/wsdl/" > 


    <wsdl:message name="sumincoming"> 
     <wsdl:part name="reqParam1" type="xsd:int"/> 
     <wsdl:part name="reqParam2" type="xsd:int"/> 
    </wsdl:message> 

    <wsdl:message name="sumoutgoing"> 
     <wsdl:part name="resParam" type="xsd:string"/> 
    </wsdl:message> 


    <wsdl:message name="helloincoming"> 
     <wsdl:part name="name" type="xsd:string"/> 
    </wsdl:message> 

    <wsdl:message name="hellooutgoing"> 
     <wsdl:part name="response" type="xsd:string"/> 
    </wsdl:message> 

    <wsdl:portType name="MyPortType"> 
     <wsdl:operation name="SumData"> 
      <wsdl:input message="tns:sumincoming"/> 
      <wsdl:output message="tns:sumoutgoing"/> 
     </wsdl:operation> 

     <wsdl:operation name="hello"> 
      <wsdl:input message="tns:helloincoming"/> 
      <wsdl:output message="tns:hellooutgoing"/> 
     </wsdl:operation> 
    </wsdl:portType> 



    <wsdl:binding name="MyBinding" type="tns:MyPortType"> 
     <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <wsdl:operation name="SumData"> 
      <soap12:operation soapAction=""/> 
      <wsdl:input> 
       <soap12:body use="literal" namespace="urn:myInputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </wsdl:input> 
      <wsdl:output> 
       <soap12:body use="literal" namespace="urn:myOutputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </wsdl:output> 
     </wsdl:operation> 

     <wsdl:operation name="hello"> 
      <soap12:operation soapAction=""/> 
      <wsdl:input> 
       <soap12:body use="literal" namespace="urn:myInputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </wsdl:input> 
      <wsdl:output> 
       <soap12:body use="literal" namespace="urn:myOutputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </wsdl:output> 
     </wsdl:operation> 

    </wsdl:binding> 

    <wsdl:service name="MyService"> 
     <!--<documentation>Returns a greeting string.</documentation>--> 
     <wsdl:port name="MyPort" binding="tns:MyBinding"> 
      <soap12:address location="http://localhost/webservices/simple/testserver.php"/> 
     </wsdl:port> 
    </wsdl:service> 

</wsdl:definition> 

заранее спасибо!

ответ

0

В визуальной студии, если вы щелкните правой кнопкой мыши проект и выберите Add -> Service Reference ... Поместите адрес wsdl в поле Address, а визуальная студия должна создать объекты для вызова вашего php soap-сервера.

Ваш адрес WSDL на примере будет

http://localhost/webservices/simple/test1.wsdl 

Visual Studio покажет список услуг:

MyPortType 
MyService 

Под моим подключ должны быть перечислены две операции

SumData 
hello 

В вашем файле wsdl есть пара исправлений.

  1. Вам нужно определить WSDL-Namespace

    Xmlns: = WSDL "http://schemas.xmlsoap.org/wsdl/"

  2. необходимо целевое пространство соответствует такое же значение, как xmlns: tns

Ниже приведен скорректированный файл wsdl.

<?xml version="1.0"?> 
<wsdl:definitions targetNamespace="urn:myTns" 
       xmlns:tns="urn:myTns" 
       xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
       xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
       xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" 
       xmlns="http://schemas.xmlsoap.org/wsdl/"> 

<wsdl:message name="sumincoming"> 
    <wsdl:part name="reqParam1" type="xsd:int"/> 
    <wsdl:part name="reqParam2" type="xsd:int"/> 
</wsdl:message> 

<wsdl:message name="sumoutgoing"> 
    <wsdl:part name="resParam" type="xsd:string"/> 
</wsdl:message> 


<wsdl:message name="helloincoming"> 
    <wsdl:part name="name" type="xsd:string"/> 
</wsdl:message> 

<wsdl:message name="hellooutgoing"> 
    <wsdl:part name="response" type="xsd:string"/> 
</wsdl:message> 

<wsdl:portType name="MyPortType"> 
    <wsdl:operation name="SumData"> 
     <wsdl:input message="tns:sumincoming"/> 
     <wsdl:output message="tns:sumoutgoing"/> 
    </wsdl:operation> 

    <wsdl:operation name="hello"> 
     <wsdl:input message="tns:helloincoming"/> 
     <wsdl:output message="tns:hellooutgoing"/> 
    </wsdl:operation> 
</wsdl:portType> 



<wsdl:binding name="MyBinding" type="tns:MyPortType"> 
    <soap12:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
    <wsdl:operation name="SumData"> 
     <soap12:operation soapAction=""/> 
     <wsdl:input> 
      <soap12:body use="literal" namespace="urn:myInputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
     </wsdl:input> 
     <wsdl:output> 
      <soap12:body use="literal" namespace="urn:myOutputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
     </wsdl:output> 
    </wsdl:operation> 

    <wsdl:operation name="hello"> 
     <soap12:operation soapAction=""/> 
     <wsdl:input> 
      <soap12:body use="literal" namespace="urn:myInputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
     </wsdl:input> 
     <wsdl:output> 
      <soap12:body use="literal" namespace="urn:myOutputNamespace" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
     </wsdl:output> 
    </wsdl:operation> 

</wsdl:binding> 

<wsdl:service name="MyService"> 
    <!--<documentation>Returns a greeting string.</documentation>--> 
    <wsdl:port name="MyPort" binding="tns:MyBinding"> 
     <soap12:address location="http://localhost/webservices/simple/testserver.php"/> 
    </wsdl:port> 
</wsdl:service> 

C# код

class Program 
{ 
    static void Main(string[] args) 
    { 
     PHPSoapClient.MyPortTypeClient client = new PHPSoapClient.MyPortTypeClient(); 
     Console.WriteLine(client.SumData(1, 2)); 
     Console.Read(); 
    } 
} 
+0

Я пытался, но я не мог, т вызвать function.could вы отправляете или загрузить источник образца пожалуйста !? –

+0

У меня возникли проблемы с файлом wsdl, который вы указали, пытаясь изучить его. –

+0

Я вставил исправленный файл wsdl. –

Смежные вопросы