2010-04-14 2 views
1

복잡한 유형의 배열을 반환하는 SOAP 서비스가 있습니다. PHP에서 NuSOAP의 정의는 다음과 같습니다 내 VisualStudio2010 C# 프로젝트에서 이제 C#이 SOAP에서 배열 유형을 잘못 파싱합니다.

// The type itself 
$server->wsdl->addComplexType(
    "Clip", 
    "complexType", 
    "struct", 
    "all", 
    "", 
    array(
     "Id" => array(
     "name" => "id", 
     "type" => "xsd:int" 
    ) 
     // ---snip--- 
    ) 
); 

// The type of the array 
$server->wsdl->addComplexType(
    "ClipList", 
    "complexType", 
    "array", 
    "sequence", 
    "", 
    array(
     "clip" => array(
     "name"  => "clip", 
     "type"  => "tns:Clip", 
     "minOccurs" => "0", 
     "maxOccurs" => "unbounded" 
    ) 
    ), 
    array(), 
    "tns:Clip" 
); 

    // The service 
    $server->register(
    "GetClipList", 
    array(), 
    array(
     "clips" => "tns:ClipList" 
    ), 
    "urn:MyNamespace", 
    "urn:MyNamespace#GetClipList", 
    "rpc", 
    "encoded", 
    "Retrieves a list of all clips." 
); 

내가 생성 된 WSDL을 기반으로 새로운 서비스를 추가했다. VS ClipList Clip[] 단일 데이터 멤버가있는 클래스를 포함하는 사용할 프록시 클래스를 만들었습니다.

지금까지 그렇게 좋았습니다. 이제 GetClipList()을 내 프록시로 호출하면 CommunicationException이라는 유형의 객체를 ClipList 유형의 객체에 Clip[] 할당 할 수 없다는 메시지가 나타납니다.

그래서 반환 된 데이터를 Clip[]으로 deserialize 한 다음 GetClipList 메서드의 반환 유형 (ClipList)을 만족하려고합니다.

프록시에서 GetClipList()의 반환 값을 Clip[]으로 수동으로 변경하면 응용 프로그램이 정상적으로 실행됩니다. 하지만 명백한 이유로 자동 생성 클래스를 변경하지 않도록하고 싶습니다.

그래서 왜 ClipList을 인스턴스화하고 데이터 멤버를 채우지 않습니까? 또는 VS가 프록시 클래스를 생성하지 않아서 GetClipList이 직접 Clip[]을 반환하는 이유는 무엇입니까?

답변

1

한 번 더 W3C SOAP 표준의 일부를 읽은 후 나는 클립 배열이 정의를 내놓았다 :

$server->wsdl->addComplexType(
    "ArrayOfClip", 
    "complexType", 
    "array", 
    "sequence", 
    "SOAP-ENC:Array", 
    array(), 
    array(
    array(
     "ref"   => "SOAP-ENC:arrayType", 
     "wsdl:arrayType" => "tns:Clip[]", 
     "minOccurs"  => "0", 
     "maxOccurs"  => "unbounded" 
    ) 
), 
    "tns:Clip" 
); 

나는 실제로 그런 정의가 이미와 이전 테스트로 내 소스에서 주석했다 wsdl.exe와 vscutil.exe가 동의하지 않는 것 같습니다. 그러나 VisualStudio의 통합 서비스 가져 오기에는이 정의가 필요합니다. 나는 구조의 배열의 문제를 해결하고 있습니다

1

:

$server->wsdl->addComplexType(
     'clsDispIds', 
     'complexType', 
     'struct', 
     'sequence', 
     '', 
     array(
       'id_disp' => array('name' => 'id_disp', 'type' => 'xsd:int'), 
       'id_loc' => array('name' => 'id_loc', 'type' => 'xsd:string') 
     ) 
); 

// array di clsDispIds 
$server->wsdl->addComplexType(
    'arrclsDispIds', 
    'complexType', 
    'array', 
    'sequence', 
    '', 
    array(
     'item' => array('name' => 'item', 'type'=>'tns:clsDispIds','minOccurs' => '0', 'maxOccurs' => 'unbounded') 
    ) 
);  

$server->register( 
    'GetIdDispCollection',     // nome operazione 
    array('id'=>'xsd:int'),     // input 
    array('return'=>'tns:arrclsDispIds'), // output 
    NAMESPACE, 
    true, 
    'document', 
    'literal', 
    'restituisce tutti i dispositivi per il canale specificato', 
    'http://schemas.xmlsoap.org/soap/encoding/' 
); 

nuSoap는 응답 생성에 버그가 있고, 따라서 복합 타입은 "항목을"필수 이름이 각 배열 요소에 자동으로 태그 "항목을"추가

는 PHP에 의해 올바른 직렬화의 내 응답, 자바 & 그물입니다

stdClass Object ( 
[return] => stdClass Object ( 
    [item] => Array ([0] => stdClass Object ([id_disp] => 11718 [id_loc] => '') 
       [1] => stdClass Object ([id_disp] => 11722 [id_loc] => '') 
       [2] => stdClass Object ([id_disp] => 11723 [id_loc] => '') 
       [3] => stdClass Object ([id_disp] => 11724 [id_loc] => '') 
      )))