程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP SOAP服務器端C#客戶端

PHP SOAP服務器端C#客戶端

編輯:關於PHP編程

最近寫了個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 ";";
}
?>
記得要先下載 nusoaphttp://www.BkJia.com/uploadfile/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);
}
結果

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved