【发布时间】:2018-12-14 07:33:11
【问题描述】:
我正在调用 WildFly (JBoss) 上运行的 SOAP 服务,其中包括此操作:
<wsdl:operation name="checkIn">
<wsdl:documentation>blah</wsdl:documentation>
<wsdl:input message="tns:checkInRequestMsg" />
<wsdl:output message="tns:checkInResponseMsg" />
<wsdl:fault name="error" message="tns:errorMsg" />
</wsdl:operation>
当我在 Fiddler 中使用无效请求调用此服务时,我收到一个 HTTP 500 响应,基本上看起来像这样(我已经稍微编辑了):
<?xml version="1.0" encoding="utf-16"?>
<SOAP:Envelope xmlns:tns="..." xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<tns:error version="1.0">
<reason>...</reason>
</tns:error>
</SOAP:Body>
</SOAP:Envelope>
当我使用 Visual Studio 2015 生成的 .NET WCF 服务代理使用相同的无效请求调用此服务时,我没有收到 .NET 异常并且响应为空。我无法解析错误响应。
代理以这种方式定义操作:
// CODEGEN: Generating message contract since the operation checkIn is neither RPC nor document wrapped.
[System.ServiceModel.OperationContractAttribute(Action="urn:checkIn", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(ConsoleApplication2.ServiceReference1.ServiceError), Action="urn:checkIn", Name="error")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
ConsoleApplication2.ServiceReference1.checkInResponse checkIn(ConsoleApplication2.ServiceReference1.checkInRequest request);
如何在 .NET 中调用该服务,以便接收解析的错误响应而不是获取空响应?我希望能够使用 .NET WCF 生成的代理,并避免解析原始 XML 响应!
【问题讨论】:
-
如果您使用添加服务参考或 svcutil.exe 来生成操作合同和数据合同,wcf 很可能正在重命名某些元素以及添加或预期包装标记。您可能需要调整 .net 生成的代码的属性。我建议为消息添加诊断跟踪,以便您可以看到来回发送的内容。您的响应可能不为空,但在由客户端通道方法处理时不会被反序列化。
标签: .net wcf soap jboss wildfly