简体   繁体   English

WCF SOAP故障类型不正确

[英]WCF SOAP Fault incorrect type

First of all, here is my setup: 首先,这是我的设置:

  • .Net 4.0 ASP.Net application .Net 4.0 ASP.Net应用程序
  • WCF service, with basicHttpBinding (soap 1.1) WCF服务,带有basicHttpBinding(肥皂1.1)
  • The reference class was generated using svcutil, with the options /useSerializerForFaults; 引用类是使用svcutil生成的,带有/ useSerializerForFaults选项; the WSDL defines all operations, and provides links to the types.xsd and the types_fault.xsd files. WSDL定义了所有操作,并提供了指向types.xsd和types_fault.xsd文件的链接。 FYI, the WSD and XSD files are common for many applications so I cannot modify them (unless of course there some major validation errors) 仅供参考,WSD和XSD文件在许多应用程序中很常见,因此我无法对其进行修改(除非存在一些主要的验证错误)

My issue stands when I send a SOAP Fault to the client : I am unable to access the correct type in the code, for the fault detail, so the client is not able to process this fault. 我的问题是当我向客户端发送SOAP Fault时:对于错误详细信息,我无法访问代码中的正确类型,因此客户端无法处理此错误。

Here is an extract of the WSDL for your understanding: 以下是WSDL的摘录,供您理解:

<wsdl:message name="CreateScheduledWorkRequest">
            <wsdl:part name="parameters" element="root:CreateScheduledWork"/>
    </wsdl:message>
    <wsdl:message name="CreateScheduledWorkResponse">
            <wsdl:part name="parameters" element="root:CreateScheduledWorkResponse"/>
    </wsdl:message>
    <wsdl:message name="CreateScheduledWorkFault">
            <wsdl:part name="parameters" element="root:CreateScheduledWorkFault"/>
    </wsdl:message>

<wsdl:portType name="ManageScheduledWorkScheduledWorkManagement">
<wsdl:operation name="CreateScheduledWork">
                    <wsdl:input name="CreateScheduledWorkRequest" message="intf:CreateScheduledWorkRequest"/>
                    <wsdl:output name="CreateScheduledWorkResponse" message="intf:CreateScheduledWorkResponse"/>
                    <wsdl:fault name="CreateScheduledWorkFault" message="intf:CreateScheduledWorkFault"/>
            </wsdl:operation>
</wsdl:portType>

<wsdl:binding name="ManageScheduledWorkScheduledWorkManagementBinding"   type="intf:ManageScheduledWorkScheduledWorkManagement">
            <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="CreateScheduledWork">
                    <wsdlsoap:operation soapAction="http://www.orange.com/MACHX/Interfaces/ManageScheduledWork/ScheduledWorkManagement/v1/CreateScheduledWork"/>
                    <wsdl:input name="CreateScheduledWorkRequest">
                            <wsdlsoap:body use="literal"/>
                    </wsdl:input>
                    <wsdl:output name="CreateScheduledWorkResponse">
                            <wsdlsoap:body use="literal"/>
                    </wsdl:output>
                    <wsdl:fault name="CreateScheduledWorkFault">
                            <wsdlsoap:fault name="CreateScheduledWorkFault" use="literal"/>
                    </wsdl:fault>
            </wsdl:operation>
</wsdl:binding>

So for example, when I send a Response back (no errors occurred), I can use the CreateScheduledWorkResponse element, and fill it correctly; 因此,例如,当我发回响应 (没有发生错误)时,可以使用CreateScheduledWorkResponse元素并正确填充它; but when a FaultException occurs, I'm only able to send back a CreateScheduledWorkFaultMessage (and not a CreateScheduledWorkFault). 但是当出现FaultException时,我只能发送回CreateScheduledWorkFaultMessage (而不是CreateScheduledWorkFault)。 And the client cannot handle this tag... 客户端无法处理此标签...

In other words, the CreateScheduledWorkFault type is not available in the code. 换句话说,CreateScheduledWorkFault类型在代码中不可用。

--> I suspect that there is something wrong when generating the code from the WSDL and XSD using svcutil , as I am not able to access the desired type in the code. ->我怀疑使用svcutil从WSDL和XSD生成代码时出了点问题 ,因为我无法访问代码中所需的类型。

I use svcutil this way: 我以这种方式使用svcutil:

svcutil /useSerializerForFaults CSW.wsdl CSW.xsd CSW_Fault.xsd svcutil / useSerializerForFaults CSW.wsdl CSW.xsd CSW_Fault.xsd

Thanks for your help, and don't hesitate if you need more details. 感谢您的帮助,如果您需要更多详细信息,请不要犹豫。

Boris 鲍里斯

My solution was to modify directly the type in the generated class... it's bad, but in my situation it was the only choice I had (normally I should never regenerate it as the WSDL will never change). 我的解决方案是直接修改生成的类中的类型……这很糟糕,但是在我的情况下,这是我唯一的选择(通常,我永远不要重新生成它,因为WSDL永远不会改变)。

Now I have another issue, but it's more namespace related, so I will open a new question for that. 现在,我还有另一个问题,但是它与名称空间有关,因此我将为此提出一个新问题。

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

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