什么是 XmlNode?

发布于 2024-11-30 10:47:04 字数 10477 浏览 1 评论 0原文

我正在尝试使用 PHP 和 nusoap 将数据提交到 Web 服务。我调用的 Web 服务操作位于此处: http://service.leads360.com /ClientService.asmx?op=AddLeads

该操作的预期参数为 username 作为字符串、password 作为字符串以及 leads 作为XmlNode。对于这个 XmlNode,他们提供了架构和 xml 文档的示例:

http:// service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd

http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads .xml

所以我复制了他们提供的 xml 文档并将其转换为一个数组,将该数组放入另一个名为 $params 的数组中用户名密码并执行

$result = $client->call('AddLeads', $params);

不幸的是,它给了我以下错误:

[faultcode] => soap:Server
    [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at LeadManager.Business.XmlHelper.RemoveNamespace(XmlNode xml, Boolean asElement) in c:\Code\DEV\LeadManager_Business\Utilities\XmlHelper.cs:line 323
   at LeadManagerService.ClientService.InsertSerializedLeads(XmlNode descriptors)
   at LeadManagerService.ClientService.InsertLeads(XmlNode descriptor)
   at LeadManagerService.Invoker 1.Invoke(ServiceContext context, String methodName, ICredentials credentials, Object parameters, Requestor requestor)
   at LeadManagerService.ClientService.AddLeads(String username, String password, XmlNode leads)
   --- End of inner exception stack trace ---

我将代码粘贴到:http://pastebin.com/7jbPGuqn

我还将我作为 Lead 参数传递的数组粘贴到下面。请告诉我该数组是否代表示例中的 xml 文档以及它是否是有效的 XmlNode

Array
(
    [Leads] => Array
        (
            [Lead] => Array
                (
                    [0] => Array
                        (
                            [Status] => Array
                                (
                                )
                            [Status_attr] => Array
                                (
                                    [StatusId] => 2
                                )
                            [Campaign] => Array
                                (
                                )
                            [Campaign_attr] => Array
                                (
                                    [CampaignId] => 3
                                )
                            [Agent] => Array
                                (
                                )
                            [Agent_attr] => Array
                                (
                                    [AgentId] => 1
                                )
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F1Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L1Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => 5
                                                    [Value] => 111111111
                                                )
                                            [4] => Array
                                                (
                                                )
                                            [4_attr] => Array
                                                (
                                                    [FieldId] => 6
                                                    [Value] => 
                                                )
                                        )
                                )
                        )
                    [1] => Array
                        (
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F2Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L2Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => 5
                                                    [Value] => 222222222
                                                )
                                        )
                                )
                        )
                    [2] => Array
                        (
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F3Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L3Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => -9999999
                                                    [Value] => 333333333
                                                )
                                        )
                                )
                        )
                )
        )
)

I am trying to submit data to a web service using PHP and nusoap. The web service operation I'm calling is located here: http://service.leads360.com/ClientService.asmx?op=AddLeads

The operation's expected parameters are username as string, password as string, and leads as XmlNode. For this XmlNode they give examples of the schema and xml doc:

http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd

http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml

So I copied the xml doc they gave and turned it into an array, put that array inside another array called $params along with username and password and executed

$result = $client->call('AddLeads', $params);

Unfortunately it is giving me the following error:

[faultcode] => soap:Server
    [faultstring] => System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at LeadManager.Business.XmlHelper.RemoveNamespace(XmlNode xml, Boolean asElement) in c:\Code\DEV\LeadManager_Business\Utilities\XmlHelper.cs:line 323
   at LeadManagerService.ClientService.InsertSerializedLeads(XmlNode descriptors)
   at LeadManagerService.ClientService.InsertLeads(XmlNode descriptor)
   at LeadManagerService.Invoker 1.Invoke(ServiceContext context, String methodName, ICredentials credentials, Object parameters, Requestor requestor)
   at LeadManagerService.ClientService.AddLeads(String username, String password, XmlNode leads)
   --- End of inner exception stack trace ---

I pasted my code at: http://pastebin.com/7jbPGuqn.

I am also pasting the array I am passing as the leads parameter below. Please tell me if the array represents the xml doc in the example and if it is a valid XmlNode.

Array
(
    [Leads] => Array
        (
            [Lead] => Array
                (
                    [0] => Array
                        (
                            [Status] => Array
                                (
                                )
                            [Status_attr] => Array
                                (
                                    [StatusId] => 2
                                )
                            [Campaign] => Array
                                (
                                )
                            [Campaign_attr] => Array
                                (
                                    [CampaignId] => 3
                                )
                            [Agent] => Array
                                (
                                )
                            [Agent_attr] => Array
                                (
                                    [AgentId] => 1
                                )
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F1Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L1Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => 5
                                                    [Value] => 111111111
                                                )
                                            [4] => Array
                                                (
                                                )
                                            [4_attr] => Array
                                                (
                                                    [FieldId] => 6
                                                    [Value] => 
                                                )
                                        )
                                )
                        )
                    [1] => Array
                        (
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F2Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L2Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => 5
                                                    [Value] => 222222222
                                                )
                                        )
                                )
                        )
                    [2] => Array
                        (
                            [Fields] => Array
                                (
                                    [Field] => Array
                                        (
                                            [0] => Array
                                                (
                                                )
                                            [1] => Array
                                                (
                                                )
                                            [0_attr] => Array
                                                (
                                                    [FieldId] => 2
                                                    [Value] => F3Name
                                                )
                                            [1_attr] => Array
                                                (
                                                    [FieldId] => 3
                                                    [Value] => L3Name
                                                )
                                            [2] => Array
                                                (
                                                )
                                            [2_attr] => Array
                                                (
                                                    [FieldId] => 4
                                                    [Value] => [email protected]
                                                )
                                            [3] => Array
                                                (
                                                )
                                            [3_attr] => Array
                                                (
                                                    [FieldId] => -9999999
                                                    [Value] => 333333333
                                                )
                                        )
                                )
                        )
                )
        )
)

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

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

发布评论

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

评论(1

聚集的泪 2024-12-07 10:47:04

与值是简单的整数或字符串的元素不同,XmlNode 是一个更复杂的结构,它是一个 XML 元素。

在服务的 WSDL 中,您将找到 AddLeads 元素的以下内容:

<s:element name="AddLeads">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="leads">
          <s:complexType mixed="true">
            <s:sequence>
              <s:any/>
            </s:sequence>
          </s:complexType>
        </s:element>
      </s:sequence>
    </s:complexType>
</s:element>

这是 AddLeads 元素的架构。该架构将用于验证您提供的标记。

请注意,usernamepassword 具有字符串类型,而 leads 是“any”复杂类型。这将意味着这样的消息:

<soapenv:Body>
  <AddLeads>
     <username>foo</username>
     <password>bar</password>
     <leads>
        You may enter ANY elements at this point
     </leads>
  </AddLeads>
</soapenv:Body>

但是“任何”复杂类型作为定义有点宽泛,因此 Web 服务的创建者决定将其限制为他们认为有用的信息。以下架构限制 AddLeads 操作上下文中的“任意”:

http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd

其中以下是有效实例:

http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads .xml

我不懂 PHP,但您的代码必须生成一条尊重 Web 服务 WSDL 类型和 leads 类型的消息。

我建议您使用 SoapUI 之类的工具来创建调用 Web 服务的请求。一旦您获得有效的消息内容并成功响应,请调整您的 PHP 代码以生成相同的格式。您还会发现(另一个工具)TCP Monitor 对于查看哪些消息非常有用在您的客户端和网络服务之间进行交换。

Unlike an element who's value is something simple as an int or string, an XmlNode is a more complex structure, it is an XML element.

Inside the WSDL of the service you will find the following for the AddLeads element:

<s:element name="AddLeads">
    <s:complexType>
      <s:sequence>
        <s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="password" type="s:string"/>
        <s:element minOccurs="0" maxOccurs="1" name="leads">
          <s:complexType mixed="true">
            <s:sequence>
              <s:any/>
            </s:sequence>
          </s:complexType>
        </s:element>
      </s:sequence>
    </s:complexType>
</s:element>

This is the schema for the AddLeads element. The schema will be used to validate the markup you provide.

Notice that username and password have the type string, while leads is "any" complex type. That will mean a message like this one:

<soapenv:Body>
  <AddLeads>
     <username>foo</username>
     <password>bar</password>
     <leads>
        You may enter ANY elements at this point
     </leads>
  </AddLeads>
</soapenv:Body>

But "any" complex type is a little bit to wide as a definition, so the creators of the web service decided to limit it to something they recognize as useful information. The following schema limits the "any" in the context of the AddLeads operation:

http://service.leads360.com/Documentation/Schemas/Client/Leads.Request.xsd

for which the following is a valid instance:

http://service.leads360.com/Documentation/Examples/Client/AddLeads.leads.xml

I don't know PHP but your code must generate a message that respects the web service WSDL types an the leads type.

I suggest you use a tool like SoapUI to create requests to call the web service. Once you get a valid message content with a successful response, adapt your PHP code to generate the same format. You will also find (another tool) the TCP Monitor very useful in seeing what messages get exchanged between your client and the web service.

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