使用多个参数从 PHP 调用 asp.net web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9711502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Call asp.net web service from PHP with multiple parameters
提问by Felasfaw
I'm using a method using SoapClient class in a php page to call a web service in an asp.net site.
我正在使用一种在 php 页面中使用 SoapClient 类的方法来调用 asp.net 站点中的 Web 服务。
Here is the php code.
这是php代码。
$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params = array( 'Param1' => 'Hello',
'Param2' => 'World!');
$result = $client->TestMethod($params)->TestMethodResult;
echo $result;
The problem is, I'm only getting the first parameter (Param1) "Hello" back and seems like there is an issue with Param2. Here is the asp.net method.
问题是,我只得到了第一个参数(Param1)“Hello”,并且似乎 Param2 存在问题。这是asp.net方法。
[WebMethod]
public string TestMethod(string Param1, string Param2)
{
return Param1 + " " + Param2;
}
What am I missing to get Hello World!
in the response?
我Hello World!
在响应中缺少什么?
回答by Darin Dimitrov
Try like this:
像这样尝试:
$client = new SoapClient("http://testurl/Test.asmx?WSDL");
$params->Param1 = 'Hello';
$params->Param2 = 'World!';
$result = $client->TestMethod($params)->TestMethodResult;
回答by M.Ganji
***********index.php******************
<?php
require_once("lib/nusoap.php");
$client = new SoapClient("http://localhost:1966/ListAndishmandan/WebServiseFinal.asmx?WSDL");
$params = array( 'Param1' => 'Moslem',
'Param2' => 'Ganji!');
$result = $client->TestMethod($params)->TestMethodResult;
print_r( $result);
$params = array( 'Param1' => 'Moslem',
'Param2' => 'Ganji!');
echo "\n \r";
$result2 = $client->ShowNameFamely($params)->ShowNameFamelyResult;
print_r( $result2);
?>
*******************WebServiseFinal.asmx?WSDL**************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for WebServiseFinal
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 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 WebServiseFinal : System.Web.Services.WebService {
public WebServiseFinal () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public string TestMethod(string Param1, string Param2)
{
return Param1 + " " + Param2;
}
[WebMethod]
public string ShowNameFamely(string Param1, string Param2)
{
return Param1 + " " + Param2;
}
}
回答by TLCW
I was googling for multi-parameter calling. All the thread did not tell the following. When php call .asmx web service, the passing of parameters MUST MATCH the variables used in the web service of :
我在谷歌上搜索多参数调用。所有的线程没有告诉以下。php调用.asmx web service时,传递的参数必须匹配web service中使用的变量:
public string XYZ(string p, string q)
The web service call has to be something like :
Web 服务调用必须类似于:
$params = array( "p" => $name1, "q" => $name2 );
p, q pairs must be named and clarified in php calling.
p, q 对必须在 php 调用中命名和澄清。