.NET 服务(使用 php)解析(soap)结果时出现问题

发布于 2024-12-20 21:58:11 字数 2090 浏览 0 评论 0原文

我在使用 PHP 连接 .NET Soap 服务器时遇到了一些问题。 我也在 StackOverflow 以及 google 上进行了一些搜索,但找不到解决方案/相同的问题。

事情是这样的。 我正在尝试从服务器获取一些数据。请求进展顺利,但响应似乎无效。

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

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

有人遇到这个问题或有正确的解决方案吗?

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

干杯 塞巴斯蒂安

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>
)

I'm running into some problems while connecting with a .NET soap server with PHP.
I've run some searches on StackOverflow as well on google, but couldn't find a solution/ same problem.

Here's the thing.
I'm trying to obtain some data from a server. The requests goes well, however the response seems to be invalid.

The response contains only one object element "any" in this object. Raw xml / xsd data is shown.

I've also tried to parse it myself using different methods (as simple_xml & domdocument) however the result is "invalid data/xml"

Has anyone run into this problem or have a proper solution.?

Below you'll find the "result" dump) of the request, if more data is needed please ask.

Cheers
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>
)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没有你我更好 2024-12-27 21:58:11

我刚刚自己解决了这个问题。我对 XML 和 SOAP 知之甚少,但根据我所做的研究,默认的 .net Web 服务使命名空间和其他包装器变得混乱。此外,php肥皂客户端使情况变得更糟并且无法创建正确的对象。您得到的响应是 1/2 对象和 1/2 XML。没有道理吧!

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

$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 Web 服务中检索到了您想要的信息。简单,对吧!

I just solved this issue myself. I know very little about XML and SOAP, but from the research I did, the default .net web-services makes a mess with namespaces and other wrappers. Further, the php soap client makes it worse and fails to make a proper object. The response you get is 1/2 object and 1/2 XML. Make no sense, right!

Well, I load the "any" element of the object and loaded it into a

$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>

And now your have retrieved the information that you wanted from the visual studio .net webserivce. easy, right!!

怪我太投入 2024-12-27 21:58:11

下面我介绍如何处理 SOAP 请求和响应。您将获得包含数据的 Object ,因此 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);

Below I present how I handle SOAP request and response. You are getting Object containing any containing your data, so do Object->any like so:

$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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文