消费到.NET SOAP服务从PHP与认证 [英] Consuming to a .NET SOAP service from PHP with authentication

查看:146
本文介绍了消费到.NET SOAP服务从PHP与认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在找了好几天了一个解决方案,这一点,但没有运气。

I've been hunting for several days for a solution to this but had no luck.

我有我的首发code从的http://www.codingfriends.com/index.php/2010/04/16/soap-client-calling-net-web-service/

I got my starter code from http://www.codingfriends.com/index.php/2010/04/16/soap-client-calling-net-web-service/ .

这里的code的调整(用假钥匙):

Here's the code as adjusted (with a fake key):

<?php
// create a connection to the local host mono .NET pull back the wsdl to get the functions names
// and also the parameters and return values
$client = new SoapClient("https://realServer/events.asmx?WSDL",
array(
  "trace"      => 1,        // enable trace to view what is happening
  "exceptions" => 0,        // disable exceptions
  "cache_wsdl" => 0)        // disable any caching on the wsdl, encase you alter the wsdl server
);

// get a response from the WSDL zend server function getQuote for the day monday
print_r( $client->GetSingleEvent(array("APIKey" => "HISY20Y4-8405-91SK-L0S7-9A17252E548A", "EventId" => "2559")));

// display what was sent to the server (the request)
echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
// display the response from the server
echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
?>

下面是实际的XML请求应该是什么样子(如肥皂UI测试)

Here's what the actual xml request should look like (as tested in Soap UI)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:cer="http://cermsystem.net/">
<soapenv:Header>
  <tem:Credentials>
     <!--Optional:-->

  <tem:APIKey>HISY20Y4-8405-91SK-L0S7-9A17252E548A</tem:APIKey></tem:Credentials>
</soapenv:Header>
<soapenv:Body>
  <tem:GetSingleEvent>
     <!--Optional:-->
     <cer:GetEventByIDRQ>
        <!--Optional:-->

     <cer:EventId>2559</cer:EventId></cer:GetEventByIDRQ>
  </tem:GetSingleEvent>
</soapenv:Body>
</soapenv:Envelope>

这是向.NET SOAP服务器后的电流输出,我从剧本获得:

This is the current output I am getting from the script after sending to .NET SOAP server:

SoapFault Object ( [message:protected] => Server was unable to process request. ---> Object reference not set to an instance of an object. 
[string:Exception:private] => [code:protected] => 0 [file:protected] => /Library/WebServer/Documents/soap6.php [line:protected] => 15 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Library/WebServer/Documents/soap6.php [line] => 15 [function] => __call [class] => SoapClient [type] => -> [args] => Array ( [0] => GetSingleEvent [1] => Array ( [0] => Array ( [APIKey] => 8F0A395B-8405-480B-871C-9A17252E548A ) ) ) ) [1] => Array ( [file] => /Library/WebServer/Documents/soap6.php [line] => 15 [function] => GetSingleEvent [class] => SoapClient [type] => -> [args] => Array ( [0] => Array ( [APIKey] => 8F0A395B-8405-480B-871C-9A17252E548A ) ) ) ) [previous:Exception:private] => [faultstring] => Server was unable to process request. ---> Object reference not set to an instance of an object. [faultcode] => soap:Server [detail] => )

Request :<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/">
<SOAP-ENV:Body>
<ns1:GetSingleEvent/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Response:<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>Server was unable to process request. ---&gt; Object reference not set to an instance of an object.</faultstring>
<detail />
</soap:Fault>
</soap:Body>
</soap:Envelope>

我觉得问题是,.NET服务器不接收的APIKey和EVENTID正确的输入,但我一直无法得到的那部分工作。是否APIKey需要发送的头的一部分?如果是的话我将如何做到这一点,结合读取WSDL

I think the problem is that the .NET server isn't receiving the right inputs for APIKey and EventId, but I've been unable to get that part to work. Does the APIKey need to be sent as part of the header? If so how would I do that in combination with reading the WSDL

推荐答案

在你的模型正确的XML,你有'APIKey而这种嵌套在证书的元素在里面,SOAP头里面。你的PHP code不会产生这一点。

In your model correct XML, you have 'APIKey' and such nested inside a 'Credentials' element, inside the SOAP header. Your PHP code won't generate this.

您需要像此功能,允许您添加页眉您的SOAP请求。要添加标题是这样的:

You need something like this function that permits you to add headers to your soap request. The header you want to add is something like this:

$ns = 'http://tempuri.org/'; //Namespace of the webservice
$headerbody = array("APIKey" => "HISY20Y4-8405-91SK-L0S7-9A17252E548A");

//Create Soap Header.        
$header = new SOAPHeader($ns, 'Credentials', $headerbody);        

//set the Headers of Soap Client. 
$client->__setSoapHeaders($header); 

在这一点上,你的要求应该工作(尽管这code是未经测试)。

At that point, your request should work (although that code is untested).

这篇关于消费到.NET SOAP服务从PHP与认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆