从.NET服务解析(soap)结果(使用php)

时间:2011-12-12 12:21:15

标签: php .net soap

使用PHP连接.NET soap服务器时遇到了一些问题。 我在谷歌上也在StackOverflow上运行了一些搜索,但找不到解决方案/同样的问题。

这就是事情。 我正在尝试从服务器获取一些数据。请求顺利,但回复似乎无效。

响应在此对象中只包含一个对象元素“any”。显示原始xml / xsd数据。

我也尝试使用不同的方法自己解析它(如simple_xml和domdocument),但结果是“invalid data / xml”

是否有人遇到此问题或有适当的解决方案。?

您将在下面找到请求的“结果”转储,如果需要更多数据,请询问。

干杯 Sebastiaan

GetArticleListResult Object
(
    [any] => <xs:schema xmlns:mstns="www.rentplus.be/webservices/ArticleList.xsd" xmlns="www.rentplus.be/webservices/ArticleList.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="dsArticleList" targetNamespace="www.rentplus.be/webservices/ArticleList.xsd" attributeFormDefault="qualified" elementFormDefault="qualified"><xs:element name="dsArticleList" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"><xs:complexType><xs:choice minOccurs="0" maxOccurs="unbounded"><xs:element name="ArticleList"><xs:complexType><xs:sequence><xs:element name="Article_Key" type="xs:string" minOccurs="0"/><xs:element name="Warehouse_Number" type="xs:string" minOccurs="0"/><xs:element name="Date_Creation" type="xs:dateTime" minOccurs="0"/><xs:element name="Date_Last_Modification" type="xs:dateTime" minOccurs="0"/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"><dsArticleList xmlns="www.rentplus.be/webservices/ArticleList.xsd"><ArticleList diffgr:id="ArticleList1" msdata:rowOrder="0" diffgr:hasChanges="inserted"><Article_Key>GELUM-LE400</Article_Key><Warehouse_Number>01</Warehouse_Number><Date_Creation>0001-01-01T00:00:00+01:00</Date_Creation><Date_Last_Modification>2011-08-10T00:00:00+02:00</Date_Last_Modification></ArticleList></dsArticleList></diffgr:diffgram>
)

2 个答案:

答案 0 :(得分:1)

我自己刚刚解决了这个问题。我对XML和SOAP知之甚少,但是根据我所做的研究,默认的.net web-services弄乱了命名空间和其他包装器。此外,php soap客户端使它变得更糟,并且无法制作正确的对象。你得到的响应是1/2对象和1/2 XML。没有意义,对吧!

好吧,我加载了对象的“any”元素并将其加载到

$wsdl= {url of your WSDL}; //assuming its some WSDL generated by MS .net or visual studio.  Something a normal human WOULD NOT WRITE. 
$client = new SoapClient($wsdl);        //create a soap client and load WSDL
$result = $client->GetQuote($param);    //get result of the soap call
$quote = $result->GetQuoteResult;       //Get the response-- its an object.  this part is weird because it's an object containing xml parts.  There is no easy path to use it.

$xml_object = new SimpleXMLElement($quote->any);  //Grab the xml part and load as partial XML --> this took forever to figure out. anger here!!

foreach ($xml_object->Quote->Plans as $plan){       //here in my data, the XML becomes a standard ARRAY--> really getting mad now.
    //grab a few items out of the array for kicks.  Don't grab all of them, cuz some switch back to XML --> make up your mind.
    $item_names=array("QuoteID","ProductID","ProductName","PlanTypeID",
        "PlanName", "Deductible","Coinsurance", "CoverageAmount",
        "Duration", "FirstPayment", "RecurringPayment"  );
    foreach ($item_names as $item_name){
        print "$item_name=".$plan->$item_name.",  ";
    }
    print "\n";
}
print "</pre>";
</pre>

现在你已经从visual studio .net webserivce中检索了你想要的信息。简单,对!

答案 1 :(得分:-1)

下面我将介绍如何处理SOAP请求和响应。您收到的Object包含any包含您的数据,Object->any也是如此:

$WS_settings = array(
    'address' => 'http://example.com.asmx?wsdl',
    'username' => 'login',
    'password' => 'pass'
);
$WS_client = new SoapClient($WS_settings['address']);

$WS_params = new stdClass();
$WS_params->Username = $WS_settings['username'];
$WS_params->Password = $WS_settings['password'];

$WS_params->IdBrand = 1;
$WS_params->IdModel = 2;
$WS_params->IdApplication = 3;

$result = $WS_client->Get_Products($WS_params)->Get_ProductsResult->any;
var_dump($result);