2009-07-16 13 views
1

私はNuSOAPライブラリを使ってSOAPを使ってリモート(php)サーバと会話するクライアントをCで構築しようとしています。 はここにいくつかのユーザのユーザ情報containtます構造体/オブジェクト使用してイム:C#構造体とNuSOAP(PHP)

public struct UserProfile { 
      public string username; 
      public string password; 
      public string email; 
      public string site; 
      public string signature; 
      public int age; 
      public int points;

をそして、これはPHPのコードです:今

server->wsdl->addComplexType(
       'UserProfile', 
       'complexType', 
       'struct', 
       'all', 
       '', 
       array(
        'username' => array('name' => 'username', 'type' => 'xsd:string'), 
        'password' => array('name' => 'password', 'type' => 'xsd:string'), 
        'email' => array('name' => 'email', 'type' => 'xsd:string'), 
        'site' => array('name' => 'site', 'type' => 'xsd:string'), 
        'signature' => array('name' => 'signature', 'type' => 'xsd:string'), 
        'age' => array('name' => 'age', 'type' => 'xsd:int'), 
        'points' => array('name' => 'username', 'type' => 'xsd:int'), 
       ) 
); 

$server->wsdl->addComplexType(
       'UserProfileArray', 
       'complexType', 
       'array', 
       '', 
       'SOAP-ENC:Array', 
       array(), 
       array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:UserProfile[]')), 
       'tns:UserProfile' 
); 

$server->register("getUserProfile", 
    array(), 
    array('return' => 'tns:UserProfileArray'), 
    $namespace, 
    false, 
    'rpc', 
    false, 
    'Get the user profile object' 
); 

function getUserProfile(){ 
    $profile['username'] = "user"; 
    $profile['password'] = "pass"; 
    $profile['email'] = "[email protected]"; 
    $profile['site'] = "u.com"; 
    $profile['signature'] = "usucsdckme"; 
    $profile['age'] = 111; 
    $profile['points'] = time()/2444; 

    return $profile; 
}

私はすでに作業ログイン機能を持っている、と私ログインしたユーザーに関する情報を取得したいのですが、これらを取得する方法はわかりません。これは、のuserinfoを取得するために使用して何イムです:

   string user = txtUser.Text; 
      string pass = txtPass.Text; 
      SimpleService.SimpleService service = new SimpleService.SimpleService(); 
      if(service.login(user, pass)){ 
       //logged in 

      } 

      SoapApp.SimpleService.UserProfile[] user = service.getUserProfile(); // THIS LINE GIVES ME AN EXCEPTION 

      MessageBox.Show(user[0].username + "--" + user[0].points);

getUserProfile()関数は、エラーが発生します。

System.Web.Services.Protocols.SoapException was unhandled 
    Message="unable to serialize result" 
    Source="System.Web.Services"

またはI 'カント解析のxml' はエラーのようなものを取得します。彼らは何をやっていると私は何をしようとすると、私は1つのオブジェクトのみではなく、複数の「MySoapObjects」が返さ取得したいということですhttp://www.sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html 差に:

私はこのために使用される記事からでした。

誰かがこれに慣れていて、助けてくれることを祈っています。ありがとうございました! よろしく、 opx

+0

あなたは、この質問に私の一日の感謝を救いました!私はあなたにビールを借りています。 – Matheno

答えて

0

あなたのgetUserProfile()メソッドがUserProfileオブジェクトの配列を返すように、PHPでWSDLを設定することが一見したようです。このメソッドを見ると、実際には単一のUserProfileオブジェクトしか返されません。C#ではオブジェクトの配列であると想定しています。

要するに、WSDLとコードが同期していません。

UserProfile user = service.getUserProfile(); 

$server->register("getUserProfile", 
    array(), 
    array('return' => 'tns:UserProfile'), 
    $namespace, 
    false, 
    'rpc', 
    false, 
    'Get the user profile object' 
); 

ます。また、このような何かにWebサービスを呼び出すC#コードを変更する必要があります:私はあなたがWSDLとメソッドを登録するコードを変更する必要があると思います次に、UserProfileArray型のWSDL登録全体を取り除くことができます。

0

WebServiceから返されるオブジェクトと同じ名前のオブジェクトをローカルに作成しようとしていたため、同じ問題が発生しました。

代わりに、サービスリファレンスがこのプロセスを管理し、WSDLから読み取った内容に基づいて私のためにオブジェクトを定義できるようにする必要がありました。

ので、「localWS」と呼ばれるサービスを参照して、その後、以下が適用されます。

localWS.ServReference ws = new localWS.ServReference(); 
localWS.ServReference.MyObject obj = localWS.ServReference.MyObject(); 
obj = localWS.ServReference.CallMethodHere();