php调用c#.NET写的webservice(亲测通过)_PHP教程
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php调用c#.NET写的webservice(亲测通过)_PHP教程,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3524字,纯文字阅读大概需要6分钟。
内容图文
![php调用c#.NET写的webservice(亲测通过)_PHP教程](/upload/InfoBanner/zyjiaocheng/175/91a17b62f28e45bdbd59f3d3255fa818.jpg)
C# 代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
///
///ibmfashion 的摘要说明
///
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[SoapDocumentService(RoutingStyle = SoapServiceRoutingStyle.RequestElement)]
//若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
// [System.Web.Script.Services.ScriptService]
public class ibmfashion : System.Web.Services.WebService {
public ibmfashion () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public int multiplication(int a, int b)
{
return a*b;
}
}
php调用c# webservice代码:
// Pull in the NuSOAP code
ob_start();
require_once('lib/nusoap.php');
$url ="http://localhost:8787/wcf/ibmfashion.asmx?wsdl";
$client = new nusoap_client($url, 'wsdl','','','','');
$client->soap_defencoding='utf-8';
$client->decode_utf8=false;
$client->xml_encoding='utf-8';
//参数转换为数组传递
$ary = array('a' => 11, 'b' => 22);
$result = $client->call('multiplication',$ary);
echo "
".print_r($result,true)."";
//错误及debug信息
if ($client->fault) {
echo '
Fault
';';
print_r($result);
echo '
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '
Error
' . $err . '';
} else {
// Display the result
echo '
Result
';';
print_r($result);
echo '
}
}
// Display the debug messages
echo '
Debug
';echo '
' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '';
?>
总结php调用c# .NET webservice常用的几种方法:
法1:
检查System32目录是否有php_soap.dll,如果没有网上下载放到这个目录下。
找到配置文件php.ini 文件, 打开以下扩展
extension = php_soap.dll
extension = php_curl.dll
extension = php_openssl.dll
PHP调用代码如下:
方法1:
$url ="http://www.ws.cn/1/Healthgrow/Service.asmx?wsdl";
$client = new SoapClient($url);
$client->soap_defencoding='utf-8';
$client->decode_utf8=false;
$client->xml_encoding='utf-8'
$result = $client->__soapCall("UserLogin",array("UserLogin"=>array(
'str' => '{"userName":"3","password":"222"}')));
if (is_soap_fault($result)) {
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}
else
{
echo print_r("return:".$result->UserLoginResult,true);
}
方法2:
同样用php_soap.dll,只是代码略有不同:
$url ="http://www.ws.cn/1/Healthgrow/Service.asmx?wsdl";
$client = new SoapClient($url);
$client->soap_defencoding='utf-8';
$client->decode_utf8=false;
$client->xml_encoding='utf-8';
$result = $client->UserLogin(array('str' => '{"userName":"3","password":"222"}'));
if (is_soap_fault($result)) {
trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
}
else
{
echo print_r("return:".$result->UserLoginResult,true);
}
方法3:
使用NuSoap是PHP环境下的WebService编程工具,用于创建或调用WebService。它是一个开源软件,是完全采用PHP语言编写的、通过HTTP收发SOAP消息的一系列PHP类,由NuSphere Corporation(http://dietrich.ganx4.com/nusoap/ )开发。NuSOAP的一个优势是不需要扩展库的支持,这种特性使得NuSoap可以用于所有的PHP环境,不受服务器安全设置的影响。
在处理过程中一定要注意WebService提供的参数是否匹配及正确。
http://www.bkjia.com/PHPjc/477901.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477901.htmlTechArticle先上结果图 C# 代码: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.Services.Protocols; //...
内容总结
以上是互联网集市为您收集整理的php调用c#.NET写的webservice(亲测通过)_PHP教程全部内容,希望文章能够帮你解决php调用c#.NET写的webservice(亲测通过)_PHP教程所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。