douxun2023 2010-05-07 02:58
浏览 65
已采纳

从PHP调用WS的丢失参数

I'm trying to call this WS from PHP:

namespace WsInteropTest
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://advantage-security.com/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class TestWs : System.Web.Services.WebService
    {
        [WebMethod]
        public string HelloWorld(int entero)
        {
            return "Hello World " + entero.ToString();
        }
    }
}

The code i use to call the WS is this:

<?php
        require_once('nusoap
usoap.php');
  $client = new nusoap_client('http://localhost/testws/TestWS.asmx?WSDL');

  $params = array(
   'entero' => 100
  );

  $result = $client->call('HelloWorld', array($params), 
      'http://advantage-security.com/HelloWorld',
      'http://advantage-security.com/HelloWorld');
  print_r($result);
  ?>

and the result is this

Hello World 0

What do you think may be the problem?

According to what i've read there is no issues with simple types between .NET (which are converted to standard soap types) and PHP.

If it is of use, here it is the WSDL.

Thanks in advance

  <?xml version="1.0" encoding="utf-8" ?> 
- <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://advantage-security.com/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://advantage-security.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
- <wsdl:types>
- <s:schema elementFormDefault="qualified" targetNamespace="http://advantage-security.com/">
- <s:element name="HelloWorld">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="1" maxOccurs="1" name="entero" type="s:int" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
- <s:element name="HelloWorldResponse">
- <s:complexType>
- <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" /> 
  </s:sequence>
  </s:complexType>
  </s:element>
  </s:schema>
  </wsdl:types>
- <wsdl:message name="HelloWorldSoapIn">
  <wsdl:part name="parameters" element="tns:HelloWorld" /> 
  </wsdl:message>
- <wsdl:message name="HelloWorldSoapOut">
  <wsdl:part name="parameters" element="tns:HelloWorldResponse" /> 
  </wsdl:message>
- <wsdl:portType name="TestWsSoap">
- <wsdl:operation name="HelloWorld">
  <wsdl:input message="tns:HelloWorldSoapIn" /> 
  <wsdl:output message="tns:HelloWorldSoapOut" /> 
  </wsdl:operation>
  </wsdl:portType>
- <wsdl:binding name="TestWsSoap" type="tns:TestWsSoap">
  <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="HelloWorld">
  <soap:operation soapAction="http://advantage-security.com/HelloWorld" style="document" /> 
- <wsdl:input>
  <soap:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:binding name="TestWsSoap12" type="tns:TestWsSoap">
  <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> 
- <wsdl:operation name="HelloWorld">
  <soap12:operation soapAction="http://advantage-security.com/HelloWorld" style="document" /> 
- <wsdl:input>
  <soap12:body use="literal" /> 
  </wsdl:input>
- <wsdl:output>
  <soap12:body use="literal" /> 
  </wsdl:output>
  </wsdl:operation>
  </wsdl:binding>
- <wsdl:service name="TestWs">
- <wsdl:port name="TestWsSoap" binding="tns:TestWsSoap">
  <soap:address location="http://localhost/testws/TestWS.asmx" /> 
  </wsdl:port>
- <wsdl:port name="TestWsSoap12" binding="tns:TestWsSoap12">
  <soap12:address location="http://localhost/testws/TestWS.asmx" /> 
  </wsdl:port>
  </wsdl:service>
  </wsdl:definitions>
  • 写回答

2条回答 默认 最新

  • duandian8251 2010-05-07 22:53
    关注

    I couldn't find out what was happening here, so i decided to use instead the Soap librery built into Php 5.2.

    The solution was this:

    $client = new SoapClient("http://localhost/testws/TestWS.asmx?WSDL");
            $params = array(
                'entero' => 77
            );
            $result = $client->HelloWorld($params);
            print_r($result->HelloWorldResult);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法