当前位置:编程学习 > php >>

PHP SOAP服务器端C#客户端

最近写了个PHP的SOAP服务器 端,实现了PHP客户端的调用,却实现不了c#客户端的调用,看完了手册找了N久也没实现其访问 ,最后试用了一下NuSOAP
SF.net上的一个开源 项目,效果 很好,很Eacy就实现了所需的功能
c#的web 服务 (服务器端)是非常容易实现的,C#客户端调用也很方便
PHP的web服务器端 一般要生成一个.wsdl的文件 ,.wsdl是一个Xml文件描述提供的服务
下面来看看我的第一个PHP web服务
<?php
/**
* ProcessSimpleType method
* @param string $who name of the person we'll say hello to
* @return string $helloText the hello   string
*/
function ProcessSimpleType($who) {
    return "Hello $who, 欢迎访问 http://www.my400800.cn ";";
}
?>
记得要先下载 nusoap/2011/0825/20110825031745407.zip

<?php
require_once("lib/nusoap/nusoap.php");
$namespace = "http://www.my400800.cn";
// create a new soap server
$server = new soap_server();
// configure our WSDL
$server->configureWSDL("SimpleService");
// set our namespace
$server->wsdl->schemaTargetNamespace = $namespace;
// register our WebMethod
$server->register(
// method name:
'ProcessSimpleType',
// parameter list:
array('name'=>'xsd:string'),
// return value(s):
array('return'=>'xsd:string'),
// namespace:
$namespace,
// soapaction: (use default)
false,
// style. rpc or document
'rpc',
// use: encoded or literal
'encoded',
// description: documentation for the method
'A simple Hello World web method');
 
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
 
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>
写完之后就可以使用了
打开.net,添加引用


下一步点击wsdl ,可以看到所提供的服务,如下图


 

 

 

C#调用代码


private void button1_Click(object sender, EventArgs e) {
SimpleService svc = new SimpleService();
string s = svc.ProcessSimpleType("400电话 VIP用户");
MessageBox.Show(s);
}
结果

补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,