我试图在 c# 中构建一个客户端,该客户端使用 NuSOAP 库与一些远程(php)服务器和 SOAP 进行通信。这里我使用一个包含某些用户的用户信息的结构/对象:
公共结构用户配置文件{ 公共字符串用户名; 公共字符串密码; 公共字符串电子邮件; 公共字符串站点; 公共字符串签名; 公开年龄; 公共 int 点;
这是PHP代码:
服务器->wsdl->addComplexType( '用户资料', '复杂类型', '结构', '全部', '', 大批( '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( '用户配置文件数组', '复杂类型', '大批', '', 'SOAP-ENC: 数组', 大批(), 数组(数组('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:UserProfile[]')), 'tns:用户配置文件' ); $server->register("getUserProfile", 大批(), 数组('return' => 'tns:UserProfileArray'), $命名空间, 错误的, 'rpc', 错误的, '获取用户配置文件对象' ); 函数 getUserProfile(){ $profile['用户名'] = "用户"; $profile['password'] = "pass"; $profile['email'] = "usern@ame"; $profile['site'] = "u.com"; $profile['signature'] = "usucsdckme"; $profile['年龄'] = 111; $profile['points'] = time() / 2444; 返回 $profile; }
现在我已经有了一个可用的登录功能,我想获取有关登录用户的信息,但我不知道如何获取这些信息。这就是我用来获取用户信息的方法:
字符串用户 = txtUser.Text; 字符串 pass = txtPass.Text; SimpleService.SimpleService 服务 = 新的 SimpleService.SimpleService(); 如果(服务登录(用户,通过)){ //登录 } SoapApp.SimpleService.UserProfile[] user = service.getUserProfile(); // 这行给了我一个例外 MessageBox.Show(user[0].username + "--" + user[0].points);
getUserProfile() 函数产生错误:
System.Web.Services.Protocols.SoapException 未处理 Message="无法序列化结果" 源="系统.Web.服务"
或者我得到类似“无法解析 xml”的错误。
我用于此的文章来自:http://www.sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html 他们所做的和我尝试做的不同之处在于我只想返回一个对象而不是多个“MySoapObjects”。
我希望有人熟悉这个并可以帮助我,在此先感谢!问候, opx