简体   繁体   English

从PHP参数到.net的肥皂调用未通过

[英]soap call to .net from php paramaters not passing

I am trying to get php to just simply pass a parameter to a .net web service however it never adds the parameter to the call, but it does call the function. 我试图让php只是将参数传递给.net Web服务,但是它从未将参数添加到调用中,但是它确实调用了该函数。

Here is the php: 这是PHP:

$client = new SoapClient("example.com/page.asmx?WSDL");
$header = new SoapHeader('example.com/', 'UserCredentials', 
    array(
        'userName' => "cory", 
        'password' => "test", 
    )
);
$client->__setSoapHeaders(array($header));

print_r($client->add("test1234"));

here is the .net 这是.net

[WebMethod]
[SoapHeader( "consumer", Required = true )]
public string add( string id )
{
    if( id == null || id != "test1234" ) {
       return "ID Invalid: " + consumer.ToString() + ":::" + id;
    }
    return "good";
}

public class UserCredentials : System.Web.Services.Protocols.SoapHeader
{
    public string userName;
    public string password;

    public override string ToString()
    {
        return userName + ":" + password;
    }
}

Whenever I run this it will print 每当我运行它时,它将打印

stdClass Object ( [addResult] => ID Invalid: cory:test::: )

So the credentials are passing in properly but the value never makes it. 因此,凭据可以正确传递,但值永远无法实现。 Any Help? 有帮助吗?

.NET simply does not do SOAP correctly. .NET根本无法正确执行SOAP。 I don't have access to the code anymore, but I believe you need to do something ridiculous like wrap your properties in another associative array under a key named 'parameters'. 我再也无法访问代码了,但是我认为您需要做一些荒谬的事情,例如将属性包装在名为“ parameters”的键下的另一个关联数组中。

Here's my answered question that got my application working. 这是使我的应用程序正常运行的已回答问题。

I think you must use an associative array for your parameters : 我认为您必须为参数使用关联数组:

array("id" => "test1234") 

So your soap call : 所以你的电话:

print_r($client->add(array("id" => "test1234"));

Documentation PHP.NET : http://php.net/manual/fr/soapclient.soapcall.php#110390 文档PHP.NET: http://php.net/manual/fr/soapclient.soapcall.php#110390

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM