我有一个调用 Java Web 服务的 C# Winforms 客户端。服务被正确调用并返回预期结果。
我一直在尝试添加肥皂扩展,直到脸色发青。它编译正确,我有充分的理由相信它正在注册......但它永远不会被调用。我尝试修改 app.config;我尝试调用“wss.SoapExtensionTypes.Add(soapInterceptor)”:同样的事情。我的 SoapException 的“Initalize()”和“ProcessMessage()”函数根本不会被调用。
问:有什么建议吗?有什么调试技巧吗?
ClientTraceExtension.cs =>
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Configuration;
using System.IO;
using System.Net;
using System.Reflection;
using System.Security.Permissions;
using GITSearchClient.ServiceReference1;
/*
* REFERENCE:
* http://msdn.microsoft.com/en-US/library/system.web.services.protocols.soapextension%28v=vs.90%29.aspx
*/
namespace GITSearchClient
{
public class ClientTraceExtension : SoapExtension
{
private Stream oldStream;
private Stream newStream;
private string filename = "c:\\temp\\soap_result.txt";
// Custom SoapExtension must override: ChainStream, GetInitializer()x2, Initialize() and ProcessMessage()
public override Stream ChainStream(Stream stream)
{
oldStream = stream;
newStream = new MemoryStream();
return newStream;
}
public override object GetInitializer(Type WebServiceType)
{
// filename = "C:\\temp\\soap_" + WebServiceType.FullName + ".txt";
//return filename;
return null;
}
public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)
{
//return filename;
return null;
}
public override void Initialize(object initializer)
{
// filename = (string)initializer;
}
public override void ProcessMessage(SoapMessage message)
{
//int i = 0;
//int j = 1 / i; // DEBUG: Stop here
switch (message.Stage)
{
case SoapMessageStage.BeforeSerialize:
break;
case SoapMessageStage.AfterSerialize:
WriteOutput(message);
break;
case SoapMessageStage.BeforeDeserialize:
WriteInput(message);
break;
case SoapMessageStage.AfterDeserialize:
break;
}
}
...
应用程序.config =>
<?xml version="1.0"?>
<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add
type="GITSearchClient.ClientTraceExtension, GITSearchClient"
priority="1"
group="0"/>
</soapExtensionTypes>
</webServices>
</system.web>
<startup>
<supportedRuntime version="v2.0.50727" sku="Client"/>
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
...
Form1.cs =>
try
{
GitSearchServiceSoapClient webService = new GitSearchServiceSoapClient();
RequestOptions requestOptions = new RequestOptions();
resp = webService.GetOosData(requestOptions, edtGroupId2.Text, "2012");
...