2017-01-16 49 views
0

好日子親愛的朋友。我打算調用PHP網絡服務,使用net winform應用程序創建SoapServer。 PHP方法recieving XML字符串作爲參數並返回JSON編碼數組:從網絡應用調用php web服務

function getPolicy($contentsXml) { 
     if ($everyting->isOK) { 
      $resultArr = createResultArray(); 
     }else{ 
      // Process errors 
     } 
     $result = json_encode($resultArr); 
     return $result; 
    } 

這是WSDL包含在PHP web服務我使用Web引用添加到視覺工作室:

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions name="XmlImportClaimWSDL" 
      targetNamespace="http://172.16.6.130/online/my.wsdl" 
      xmlns:tns="http://172.16.6.130/online/my.wsdl" 
      xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
      xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 

<wsdl:types> 
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://tempuri.org/" > 
     <element name="getPolicy"> 
      <complexType> 
       <sequence> 
        <element minOccurs="0" maxOccurs="1" name="contentsXml" type="xsd:string" /> 
       </sequence> 
      </complexType> 
      </element> 
      <element name="getPolicyResponse"> 
      <complexType> 
       <sequence> 
        <element minOccurs="0" maxOccurs="1" name="contentsXml" type="xsd:json" /> 
       </sequence> 
      </complexType> 
     </element> 
    </xsd:schema> 
</wsdl:types> 
    <wsdl:message name="getPolicyRequest"> 
    <wsdl:part name="requestParam" type="xsd:string"/> 
    </wsdl:message> 
    <wsdl:message name="getPolicyResponse"> 
    <wsdl:part name="responseParam" type="xsd:string"/> 
    </wsdl:message> 
    <wsdl:portType name="ServerClaimSoapType"> 
    <wsdl:operation name="getPolicy"> 
     <wsdl:input message="tns:getPolicyRequest" /> 
     <wsdl:output message="tns:getPolicyResponse" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="ServerClaimSoapBinding" type="tns:ServerClaimSoapType"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> 
    <wsdl:operation name="getPolicy"> 
     <soap:operation soapAction="http://php-server-address/"/> 
    <wsdl:input> 
     <soap:body use="literal" /> 
     </wsdl:input> 
    <wsdl:output> 
     <soap:body use="literal" /> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="ServerClaim"> 
    <wsdl:port name="ServerClaimSoap" binding="tns:ServerClaimSoapBinding"> 
     <soap:address location="http://php-server-address/phpSoapService.php" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

正如我從提琴手可以看到的,PHP接收參數並返回正確的json對象,但在網絡代碼中結果始終爲空。淨代碼:

PhpSoapObject client = new PhpSoapObject(); 
var result = client.getPolicy(PredifenedXmlString); 

所以結果變量總是空;我的猜測是wsdl綁定。我對這種情況進行了很多搜索。我已經意識到,使用PHP網絡服務與網絡框架沒有nusoap記錄非常差。感謝大家閱讀這麼長的問題。

回答

0

所以經過很多試驗,現在一切都在運轉。感謝Eclipse wsdl編輯器,繼電器很棒的工具。

<?xml version="1.0" encoding="utf-8"?> 
<wsdl:definitions name="XmlImportClaimWSDL" 
      targetNamespace="http://172.16.6.130/online/" 
      xmlns:tns="http://172.16.6.130/online/" 
      xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
      xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" 
      xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
      xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" 
      xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 

<wsdl:types> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://172.16.6.130/online/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" > 
    <xsd:element name="getPolicy"> 
      <xsd:complexType> 
       <xsd:sequence> 

        <xsd:element minOccurs="0" maxOccurs="1" name="contentsXml" type="xsd:string" /> 
       </xsd:sequence> 
      </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="getPolicyResponse"> 
      <xsd:complexType> 
       <xsd:sequence> 

        <xsd:element minOccurs="0" maxOccurs="1" name="getPolicyResult" type="xsd:string" /> 
       </xsd:sequence> 
      </xsd:complexType> 
     </xsd:element> 
    </xsd:schema> 
</wsdl:types> 
    <wsdl:message name="getPolicyRequest"> 
    <wsdl:part name="requestParam" type="xsd:string"/> 
    </wsdl:message> 
    <wsdl:message name="getPolicyResponse"> 
    <wsdl:part name="responseParam" type="xsd:string"/> 
    </wsdl:message> 
    <wsdl:portType name="ServerClaimSoapType"> 
    <wsdl:operation name="getPolicy"> 
     <wsdl:input message="tns:getPolicyRequest" /> 
     <wsdl:output message="tns:getPolicyResponse" /> 
    </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="ServerClaimSoapBinding" type="tns:ServerClaimSoapType"> 
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/> 
    <wsdl:operation name="getPolicy"> 
     <soap:operation soapAction="http://172.16.6.130/online/getPolicy" /> 
     <wsdl:input> 
      <soap:body use="literal" namespace="http://172.16.6.130/online/"/> 
     </wsdl:input> 
     <wsdl:output> 
      <soap:body use="literal" namespace="http://172.16.6.130/online/"/> 
     </wsdl:output> 
    </wsdl:operation> 
     </wsdl:output> 
    </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="ServerClaim"> 
    <wsdl:port name="ServerClaimSoap" binding="tns:ServerClaimSoapBinding"> 
     <soap:address location="http://172.16.6.130/phpSoapService.php" /> 
    </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

的主要問題是incorect 架構命名空間結合體命名空間丟失:如PHP WSDL應該被定義。我希望這會幫助某人。 P.S. Stackoverflow是搜索您的問題的最佳地點。