首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SOAP服务调用-获取错误元素的非法请求格式

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

Stack Overflow用户
提问于 2019-09-16 23:11:30
回答 1查看 45关注 0票数 0

我们正在集成来自第三方的服务。他们最近升级了他们的服务,现在有了新的wsdl,我不断得到“元素的非法请求格式”。

根据我的调查,问题似乎出在main元素上添加的xmlns上。如果我使用SOAPUI并从main元素中删除了xmlns,它可以工作,但是visual studio会根据wsdl中定义的内容自动添加它。

有趣的是,对于它们以前的wsdl,服务使用包含的xmlns工作,只有在使用新的wsdl时,它才抛出异常。

关于wsdl,我只知道他们使用了JD 12并手动创建了wsdl,但是经过比较,它看起来与旧的相似,唯一的区别是xmlns中的名称。

这是visual studio创建的请求:

代码语言:javascript
复制
<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>

"xmlns="http://gna160ws/Management.wsdl/types/"“导致了问题。

响应:

代码语言:javascript
复制
<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>

当提交相同的请求,但没有xmlns时,我得到一个有效的响应。示例:

代码语言:javascript
复制
<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>

响应:

代码语言:javascript
复制
<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>

此外,如果我在xmlns后面添加一个限定符,那么它也可以工作??示例:

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

我一直在与他们这边的开发人员合作,但我们还没有能够确定问题。

如果有人能帮助我或为我指明正确的方向,我将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2019-09-16 23:17:41

您是否使用新的WSDL更新了您的服务引用?

或者,您可以从Rick Strahl尝试此answer:覆盖以下函数以添加自定义名称空间。

代码语言:javascript
复制
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到他的完整文章

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57959764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档