gpt4 book ai didi

c# - 为什么我的 C# Soap Extension 没有被调用?

转载 作者:可可西里 更新时间:2023-11-01 09:11:02 27 4
gpt4 key购买 nike

我有一个调用 Java 网络服务的 C# Winforms 客户端。服务被正确调用并返回预期结果。

我一直在尝试添加 Soap Extension,直到脸色发青。它编译正确,我有充分的理由相信它正在注册......但它永远不会被调用。我尝试修改 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;
}
}
...

应用程序配置 =>

<?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");
...

最佳答案

我认为您在这里将新旧混合在一起,即 ASMX Web 服务与 WCF,请参阅 this类似问题的问题。看看约翰的回答。

关于c# - 为什么我的 C# Soap Extension 没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14168357/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com