C# 将信息传递给应用了SoapExtensionAttribute的对象
在我的应用程序中,我正在调用一个web服务,通过使用SoapExtension和SoapExtensionAttribute,我可以拦截传入和传出的SOAP消息,以便进行日志记录。我使用中的示例作为输入。 但现在我想更进一步。我有一个Windows客户端,它调用我的类(在一个单独的项目中),然后该类调用web服务。我现在可以截获SOAP消息,但我不想直接将它们记录到文件中,而是想将这些消息传递回调用web服务的类,以及调用我的类的客户端。以下是我迄今为止所做的代码更改:C# 将信息传递给应用了SoapExtensionAttribute的对象,c#,soap,custom-attributes,soap-extension,C#,Soap,Custom Attributes,Soap Extension,在我的应用程序中,我正在调用一个web服务,通过使用SoapExtension和SoapExtensionAttribute,我可以拦截传入和传出的SOAP消息,以便进行日志记录。我使用中的示例作为输入。 但现在我想更进一步。我有一个Windows客户端,它调用我的类(在一个单独的项目中),然后该类调用web服务。我现在可以截获SOAP消息,但我不想直接将它们记录到文件中,而是想将这些消息传递回调用web服务的类,以及调用我的类的客户端。以下是我迄今为止所做的代码更改: priv
private String ExtractFromStream(Stream target)
{
if (target != null)
return (new StreamReader(target)).ReadToEnd();
return "";
}
public void WriteOutput(SoapMessage message)
{
newStream.Position = 0;
string soapOutput = ExtractFromStream(newStream);
newStream.Position = 0;
Copy(newStream, oldStream);
}
public void WriteInput(SoapMessage message)
{
Copy(oldStream, newStream);
newStream.Position = 0;
string soapInput= ExtractFromStream(newStream);
newStream.Position = 0;
}
现在,我想将soapInput和soapOutput传递回保存应用此属性的方法的类。有没有关于我应该怎么做的线索?对于碰巧路过的任何人,以下是解决方案: SoapMessage对象不包含有关我的客户端的任何信息。但是,我可以将此对象强制转换为SoapClientMessage对象,然后我就可以访问我的web服务。如果我现在向这个webservice添加一个方法(通过创建一个新的公共分部类),我可以像这样访问它的属性和方法(纯粹是一个示例!): 您可以通过创建新的公共分部类并向其添加方法、属性和任何您喜欢的内容,将方法(如本例中的MyMethod)添加到WebServiceClass中
private String ExtractFromStream(Stream target)
{
if (target != null)
return (new StreamReader(target)).ReadToEnd();
return "";
}
public void WriteOutput(SoapMessage message)
{
newStream.Position = 0;
string soapOutput = ExtractFromStream(newStream);
SoapClientMessage soapClient = (SoapClientMessage)message;
WebServiceClass webservice = (WebServiceClass)soapClient.Client;
webservice.MyMethod(soapOutput); //Use your own method here!
newStream.Position = 0;
Copy(newStream, oldStream);
}
public void WriteInput(SoapMessage message)
{
Copy(oldStream, newStream);
newStream.Position = 0;
string soapInput= ExtractFromStream(newStream);
SoapClientMessage soapClient = (SoapClientMessage)message;
WebServiceClass webservice = (WebServiceClass)soapClient.Client;
webservice.MyMethod(soapInput);
newStream.Position = 0;
}