• 技术文章 >php教程 >php手册

    PHP SOAP服务器端C#客户端

    2016-06-13 10:43:55原创265
    最近写了个PHP的SOAP服务器 端,实现了PHP客户端的调用,却实现不了c#客户端的调用,看完了手册找了N久也没实现其访问 ,最后试用了一下NuSOAP
    SF.net上的一个开源 项目,效果 很好,很Eacy就实现了所需的功能
    c#的web 服务 (服务器端)是非常容易实现的,C#客户端调用也很方便
    PHP的web服务器端 一般要生成一个.wsdl的文件 ,.wsdl是一个Xml文件描述提供的服务
    下面来看看我的第一个PHP web服务
    /**
    * 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

    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);
    }
    结果

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    上一篇:PHP中出现Notice: Undefined index的三种解决办法 下一篇:php连接MySQL数据库的一些问题

    相关文章推荐

    • 通过对php一些服务器端特性的配置加强php的安全• 一段导出数据库的代码• Apache服务器的用户认证 (转)• 基于Windows下Apache PHP5.3.1安装教程• 继续收藏一些PHP常用函数第1/2页

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网