注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 小五思科技术学习笔记之SSH
 帮助

C#调用PHP写的WebService


2008-01-20 16:54:49
 标签:PHP C# WebService   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://approlife.blog.51cto.com/304821/60025
1.server.php
<?php
    class Result{
  function add($a,$b){
      return $a+$b;
  }
    }
?>
2.kobetest.wsdl
<?xml version='1.0' encoding='UTF-8'?>

<!-- WSDL file generated by Zend Studio. -->

<definitions name="kobetest" targetNamespace="urn:kobetest" xmlns:typens="urn:kobetest" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
    <message name="add">
  <part name="a" type="xsd:string"/>
  <part name="b" type="xsd:string"/>
    </message>
    <message name="addResponse">
  <part name="addReturn" type="xsd:string"/>
    </message>
    <portType name="ResultPortType">
  <operation name="add">
      <input message="typens:add"/>
      <output message="typens:addResponse"/>
  </operation>
    </portType>
    <binding name="ResultBinding" type="typens:ResultPortType">
  <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="add">
      <soap:operation soapAction="urn:ResultAction"/>
      <input>
    <soap:body namespace="urn:kobetest" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </input>
      <output>
    <soap:body namespace="urn:kobetest" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
      </output>
  </operation>
    </binding>
    <service name="kobetestService">
  <port name="ResultPort" binding="typens:ResultBinding">
      <soap:address location="http://192.168.1.55/server.php"/>
  </port>
    </service>
</definitions>
3.在VS2005中“添加web引用”,然后在代码里调用webservice就OK了。
PS:这里只是简单的写了基本过程。有些细节的地方没注明,需要的朋友可以留言联系我。

本文出自 “技术旅途上蹒跚的步行者” 博客,请务必保留此出处http://approlife.blog.51cto.com/304821/60025





    文章评论
 
2008-01-21 10:16:31
不错的 东东

2008-06-30 17:47:08
请教您,比较急着解决这个问题。
php写的webservice如下,请问,如何用c#调用?(winform界面中添加一个textbox,一个button,button如何调用webservice?)
<?php
function add($x, $y){
     return $x + $y;
}

function add2($a, $b) {
     return $a + $b;
}

$soap = new SoapServer('http://202.117.83.190/wsdl/add.wsdl');
$soap->addFunction(array('add', 'add2'));
$soap->handle();

?>

2008-07-01 14:39:46
博主是不是不常上线啊。等...

2008-07-01 22:37:01
把QQ或者MSN留下,咱们谈

2008-07-03 19:41:50
我的qq号 34408182
麻烦博主看到后把我这条留言删掉,谢了。

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: