简体   繁体   English

SOAP服务调用-获取错误的元素非法请求格式

[英]SOAP Service call - Getting error Illegal Request format for element

We are integrating a service from a third party. 我们正在整合第三方提供的服务。 They have recently upgraded their service, and now with the new wsdl, I keep getting "Illegal Request format for Element". 他们最近升级了服务,现在有了新的wsdl,我不断收到“ Element的非法请求格式”。

From my investigations the problem seems to be with the xmlns that is added on the main element. 从我的调查来看,问题似乎出在添加在main元素上的xmlns上。 If I use SOAPUI and remove the xmlns from the main element, it works, however visual studio adds it automatically in accordance with whats defined in the wsdl. 如果我使用SOAPUI并从主要元素中删除xmlns,则它可以工作,但是Visual Studio会根据wsdl中定义的内容自动添加它。

What is interesting is that with their previous wsdl, the service works with the xmlns included, it is only with the new wsdl that it throws an exception. 有趣的是,对于以前的wsdl,该服务可与包含的xmlns一起使用,只有新的wsdl会引发异常。

In terms of the wsdl, all I know is that they used JD 12 and manually created the wsdl, however upon comparing it, it looks similar to the old one with the name in the xmlns being the only difference. 就wsdl而言,我所知道的是,他们使用JD 12并手动创建了wsdl,但是相比之下,它看起来与旧版本类似,唯一的区别在于xmlns中的名称。

This is the request visual studio creates: 这是Visual Studio创建的请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <extractacccategElement xmlns="http://gna160ws/Management.wsdl/types/">
            <xSecurity>
                <timekey></timekey>
                <authkey></authkey>
                <publkey></publkey>
                <version>1.x</version>
            </xSecurity>
            <xRequest1>
                <supplierno></supplierno>
            </xRequest1>
        </extractacccategElement>
    </s:Body>
</s:Envelope>

With the "xmlns="http://gna160ws/Management.wsdl/types/"" causing the problem. 与“ xmlns =” http://gna160ws/Management.wsdl/types/“”引起问题。

Response: 响应:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <env:Header/>
   <env:Body>
      <srvc:extractacccategElementResponse xmlns="http://gna160ws/Management" xmlns:srvc="http://gna160ws/Management">
         <srvc:result>
            <response1Out>
               <origin>gna160.extractacccategElement</origin>
               <invsql>1200</invsql>
               <message>Illegal Request format for extractacccategElement.</message>
            </response1Out>
         </srvc:result>
      </srvc:extractacccategElementResponse>
   </env:Body>
</env:Envelope>

When submitting the same request, but without the xmlns, I get a valid response. 当提交相同的请求但没有xmlns时,我得到一个有效的响应。 Example: 例:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <extractacccategElement>
            <xSecurity>
                <timekey></timekey>
                <authkey></authkey>
                <publkey></publkey>
                <version>1.x</version>
            </xSecurity>
            <xRequest1>
                <supplierno></supplierno>
            </xRequest1>
        </extractacccategElement>
    </s:Body>
</s:Envelope>

Response: 响应:

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <env:Body>
    <ns0:extractacccategElementResponse xmlns="http://gna160ws/Management" xmlns:srvc="http://gna160ws/Management">
       <ns0:result>
          <ns0:acccategOut>
                <ns0:invsql>0</ns0:invsql>
                <ns0:message>Success</ns0:message>
                <ns0:origin>gna160pkg.ExtractAccCateg</ns0:origin>
                <ns0:stage>1</ns0:stage>
                <ns0:acccategcode>A</ns0:acccategcode>
                <ns0:acccategname>AAA</ns0:acccategname>
          </ns0:acccategOut>
       </ns0:result>
    </ns0:extractacccategElementResponse>
    </env:Body>
</env:Envelope>

Additionally, if I add a qualifer after the xmlns then it also works?? 另外,如果我在xmlns之后添加一个限定词,那么它也可以工作? Example: 例:

xmlns:hello="http://gna160ws/Management.wsdl/types/" xmlns:hello =“ http://gna160ws/Management.wsdl/types/”

I have been working collaboratively with the developer on their side and we have not yet been able to identify the problem. 我一直在与开发人员合作,但是我们还无法确定问题所在。

If anyone could help or point me in the right direction, it would be greatly appreciated. 如果有人可以帮助或指出正确的方向,将不胜感激。

Did you update your service reference with the new WSDL? 您是否使用新的WSDL更新了服务参考?

Alternatively you can try this answer from Rick Strahl: override the following function to add a custom namespace. 或者,您可以尝试使用Rick Strahl的答案 :覆盖以下函数以添加自定义名称空间。

protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
{
        writer.WriteStartElement("soapenv", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
        writer.WriteAttributeString("xmlns", "oas", null, "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
        writer.WriteAttributeString("xmlns", "v2", null, "http://www.royalmailgroup.com/api/ship/V2");
        writer.WriteAttributeString("xmlns", "v1", null, "http://www.royalmailgroup.com/integration/core/V1");
        writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
        writer.WriteAttributeString("xmlns", "xsd", null, "http://www.w3.org/2001/XMLSchema");            
}

Link to his complete article 链接到他的完整文章

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

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