您的位置:首页 > 编程语言 > ASP

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

2014-03-30 15:52 666 查看
自己写的代码

<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐