2012-05-15 49 views
0

我試圖將SoapExtension添加到使用Web引用調用Java Web服務的項目中。我所有的代碼是在.NET 4.0中.Net Web服務客戶端SoapExtension擰緊來自Java Web服務的響應消息

我只是增加了一個空的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,我可以從服務器接收任何回報。

我用菲德勒跟蹤傳出和回覆信息,我回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響應。

這裏有什麼問題?

回答

2

我認爲它是因爲過程消息方法是空的。我有完全相同的問題,我的過程消息方法只處理序列化後的情況,只要我反序列化之前處理過程,一切工作正常:

case SoapMessageStage.BeforeDeserialize: 
{ 
    Copy(wireStream, appStream); 
    appStream.Position = 0; 
    break; 
}