2010-06-08 5 views
2

웹 서비스에 익숙해 져서 여기에서 근본적인 실수를 저 지르면 사과드립니다.WCF를 사용하여 PHP SOAP 서비스를 사용하는 방법

저는 PHP를 사용하여 SOAP 서비스를 구축했습니다. 서비스는 SOAP 1.2와 호환되며 WSDL을 사용할 수 있습니다. 세션을 활성화하여 로그인 상태 등을 추적 할 수 있습니다.

메시지 보안 (메시지 수준 보안)이 필요하지 않습니다.이 서비스는 전송 보안 (HTTPS)이 필요합니다. 드물게 사용되며, 공연은 그다지 문제가되지 않습니다.

전혀 작동하지 않는 데 어려움을 겪고 있습니다. C#은 몇 가지 불명확 한 예외를 던졌습니다 ("서버가 잘못된 SOAP 오류를 반환했습니다. 자세한 내용은 InnerException을 참조하십시오.", "정규화 된 이름 'rpc : ProcedureNotPresent'에서 사용 된 언 바운드 접두사"라고 함). 그러나 PHP SOAP 클라이언트 예상대로 작동합니다 (세션 및 모두 포함).

지금까지 다음 코드를 작성했습니다. 참고 :

<?php 

class Verification_LiteralDocumentProxy { 

    protected $instance; 

    public function __call($methodName, $args) 
    { 
     if ($this->instance === null) 
     { 
      $this->instance = new Verification(); 
     } 

     $result = call_user_func_array(array($this->instance, $methodName), $args[0]); 
     return array($methodName.'Result' => $result); 
    } 
} 

class Verification { 

    private $guid = ''; 
    private $hwid = ''; 

    /** 
    * Initialize connection 
    * 
    * @param string GUID 
    * @param string HWID 
    * @return bool 
    */ 
    public function Initialize($guid, $hwid) 
    { 
     $this->guid = $guid; 
     $this->hwid = $hwid; 
     return true; 
    } 

    /** 
    * Closes session 
    * 
    * @return void 
    */ 
    public function Close() 
    { 
     // if session is working, $this->hwid and $this->guid 
     // should contain non-empty values 
    } 
} 

// start up session stuff 
$sess = Session::instance(); 

require_once 'Zend/Soap/Server.php'; 
$server = new Zend_Soap_Server('https://www.somesite.com/api?wsdl'); 

$server->setClass('Verification_LiteralDocumentProxy'); 

$server->setPersistence(SOAP_PERSISTENCE_SESSION); 

$server->handle(); 

WSDL : 실제 코드의 양을, 나는 최소한의 코드 구성을 클래스 (들) 서비스를 통해 노출을 포함하여 (젠드 비누 서버 라이브러리를 사용하여)

PHP의 SOAP 서버를 게시하고 인해 :

<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="https://www.somesite.com/api" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="Verification" targetNamespace="https://www.somesite.com/api"> 
    <types> 
     <xsd:schema targetNamespace="https://www.somesite.com/api"> 
      <xsd:element name="Initialize"> 
       <xsd:complexType> 
        <xsd:sequence> 
         <xsd:element name="guid" type="xsd:string"/> 
         <xsd:element name="hwid" type="xsd:string"/> 
        </xsd:sequence> 
       </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="InitializeResponse"> 
       <xsd:complexType> 
        <xsd:sequence> 
         <xsd:element name="InitializeResult" type="xsd:boolean"/> 
        </xsd:sequence> 
       </xsd:complexType> 
      </xsd:element> 
      <xsd:element name="Close"> 
       <xsd:complexType/> 
      </xsd:element> 
     </xsd:schema> 
    </types> 
    <portType name="VerificationPort"> 
     <operation name="Initialize"> 
      <documentation> 
       Initializes connection with server</documentation> 
      <input message="tns:InitializeIn"/> 
      <output message="tns:InitializeOut"/> 
     </operation> 
     <operation name="Close"> 
      <documentation> 
       Closes session between client and server</documentation> 
      <input message="tns:CloseIn"/> 
     </operation> 
    </portType> 
    <binding name="VerificationBinding" type="tns:VerificationPort"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <operation name="Initialize"> 
      <soap:operation soapAction="https://www.somesite.com/api#Initialize"/> 
      <input> 
       <soap:body use="literal"/> 
      </input> 
      <output> 
       <soap:body use="literal"/> 
      </output> 
     </operation> 
     <operation name="Close"> 
      <soap:operation soapAction="https://www.somesite.com/api#Close"/> 
      <input> 
       <soap:body use="literal"/> 
      </input> 
      <output> 
       <soap:body use="literal"/> 
      </output> 
     </operation> 
    </binding> 
    <service name="VerificationService"> 
     <port name="VerificationPort" binding="tns:VerificationBinding"> 
      <soap:address location="https://www.somesite.com/api"/> 
     </port> 
    </service> 
    <message name="InitializeIn"> 
     <part name="parameters" element="tns:Initialize"/> 
    </message> 
    <message name="InitializeOut"> 
     <part name="parameters" element="tns:InitializeResponse"/> 
    </message> 
    <message name="CloseIn"> 
     <part name="parameters" element="tns:Close"/> 
    </message> 
</definitions> 

그리고 마지막으로, WCF C# 소비자 코드 :

[ServiceContract(SessionMode = SessionMode.Required)] 
public interface IVerification 
{ 
    [OperationContract(Action = "Initialize", IsInitiating = true)] 
    bool Initialize(string guid, string hwid); 

    [OperationContract(Action = "Close", IsInitiating = false, IsTerminating = true)] 
    void Close(); 
} 

class Program 
{ 
    static void Main(string[] args) 
    { 
     WSHttpBinding whb = new WSHttpBinding(SecurityMode.Transport, true); 

     ChannelFactory<IVerification> cf = new ChannelFactory<IVerification>(
      whb, "https://www.somesite.com/api"); 

     IVerification client = cf.CreateChannel(); 

     Console.WriteLine(client.Initialize("123451515", "15498518").ToString()); 
     client.Close(); 
    } 
} 

아이디어가 있으십니까? 여기서 내가 뭘 잘못하고 있니?

답변

2

wsdl에서 클라이언트 프록시 생성을 시도 했습니까? 데이터 계약이있는 로컬 복사본 (XML 스키마) 또는 호스팅 된 wsdl.

간단한 C# 콘솔 응용 프로그램을 만들고 wsdl에서 '서비스 참조 추가'를 수행하고 프록시를 만들 수 있어야합니다. 클라이언트 코드가 자동으로 생성되고 app.config에 바인딩 정보와 끝점이 포함됩니다.

+0

아니요. 내가 다시 이것을 필요로 할 때 언젠가 시도 할 것이고, 나는 다른 접근법으로 바꿨다. 어쨌든 고마워. –

관련 문제