我尝试将 SoapExtension 添加到我的项目中,该项目使用 Web 引用来调用 Java Web 服务。我所有的代码都在 .Net 4.0 中
我刚刚添加了一个空的 SoapExtension
public class MyServiceSoapExtension : SoapExtension
{
private Stream inwardStream;
private Stream outwardStream;
public override object GetInitializer(Type serviceType)
{
return serviceType;
}
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
return null;
}
public override void Initialize(object initializer)
{
}
public override Stream ChainStream(Stream stream)
{
outwardStream = stream;
inwardStream = new MemoryStream();
return inwardStream;
}
public override void ProcessMessage(SoapMessage message)
{
}
}
我在客户的 app.config 中添加了:
<system.web>
<webServices>
<soapExtensionTypes>
<add type="MyServiceClient.MyServiceSoapExtension, MyServiceClient" priority="1" />
</soapExtensionTypes>
</webServices>
</system.web>
我相信上面的代码没有任何改变,当我运行它时,我在方法中抛出了Response is not well-formed XML.
一个Root element is missing.
异常System.Web.Services.Protocols.SoapClientType.Invoke
(我已经打开了 CLR 调试)。如果我删除 app.config 中的配置以绕过 SoapExtension,我可以接收来自服务器的任何返回。
我使用 Fiddler 来跟踪传出和响应消息,我从服务器返回的 SOAP 是
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: javax.xml.transform.stax.StAXResult </faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
我相信这是一个有效的 SOAP 响应。
这里有什么问题?