PHP 调用asp.net Web Services服务问题总结

本文详细介绍了使用PHP调用Java ASP.NET WebServices服务的过程,包括SOAP客户端的创建、参数传递、返回值解析等关键步骤,并通过实际代码示例展示了如何解决在调用过程中遇到的问题,如弱类型语言的转换不便。文章还对比了不同参数调用方式,提供了C#服务端实现供参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

自己写的代码


<html>
<head>
<title>
测试页面
</title>

</head>

<a href="http://wwww.baidu.com">百度</a>

        <?php
    

 

(一)

 

  $soap = new SoapClient("http://localhost:8035/Service1.svc?wsdl");

  

$sum = $soap->GetData(array('value'=>5));
   foreach ($sum as $s) {
   echo $s;
  }

 

(二)

 $soap = new SoapClient("http://localhost:8035/Service1.svc?wsdl");

$myStrs="";
 
  $sum = $soap->isExistUser(array  ('UserName'=>'admin1','PassWord'=>'e00cf25ad42683b3df678c61f42c6bda','visitAdress'=>'127.0.0.1'));
   foreach ($sum as $s) {
   echo $s;
   $myStrs=$s;
  }

  echo '</br>';
 
  echo $myStrs;
  echo strlen($myStrs);
  
    
  echo '</br>';
 
  //$test1="'{\"nu\":".$s."}'";
 
  $myStr123=substr($myStrs,1,strlen($myStrs)-2);
 
  echo $myStr123;
 
  $obj1=json_decode($myStr123);
  echo $obj1->UserID;
  
 
echo '</br>';
echo '</br>';


//echo $sum->UserID;

$str = '{"UserID":"2"}';

$obj1=json_decode($str);
echo $obj1->UserID;

  
echo '</br>';

$json_string='{"id":1,"name":"foo","email":"foo@foobar.com","interest":["wordpress","php"]} ';
$obj=json_decode($json_string);
echo $obj->name; //prints foo

echo "</br>";
echo $obj->interest[1]; //prints php

 

 

 

  ?>

 

<a href="mysecond.php?id=25">测试页面</a>
</html>

 

 

 

参考:

 

PHP 调用jave  asp.net Web Services服务问题总结

Catchable fatal error: Object of class stdClass could not be converted to string in ...

PHP是弱类型语言,转换非常不方便。

< ?php
//soap 客户端
$client=new SoapClient('http://localhost:1278/WebSite1/WebService.asmx?WSDL');
$hello = $client->HelloWorld();
echo $hello;//不可以直接输出会有以下错误提示,但在Java下却正常。
//必须采用以下循环输出即可
foreach ($hello as $h)
{
echo $h;
}
?>

调用多个参数

$sum = $client->Sun(array('a'=>5,'b'=>85));
foreach ($sum as $s) {
echo $s;
}

C#:

[WebMethod]
public String Sun(Int32 a ,Int32 b)
{
return a + b+"";
}

//另一种调用方法
$sum = $client->__call('Sun',array('parameters'=>array('a'=>4,'b'=>4)));
foreach ($sum as $s) {
echo $s;
}


服务器端编写:
访问: http://localhost/index.php?wsdl

 

http://blog.sina.com.cn/s/blog_4beab9e201015l8f.html

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值