Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Services (http://www.velocityreviews.com/forums/f64-asp-net-web-services.html)
-   -   Complex webservice scenario. (http://www.velocityreviews.com/forums/t785845-complex-webservice-scenario.html)

jens Jensen 02-13-2006 09:11 PM

Complex webservice scenario.
 
Hello ,
i'm calling a webservice generated with oracle webservice java tools.

I'm not able to add a web reference to a .net client the usual way with
visual studio 2005.

I was therefore provided with a set of Dll that implement the proxy needed
to consume this web service.
I'm now wrapping these dlls in a .Net webservice that can be consumed with
Visual studio the familliar way.

Below the code inside the Dlls.
The job is done by calling : xmldocument doc processMessage(xmldocument
doc);




********************
using System;

using System.Collections.Generic;

using System.Text;

using System.Web;

using System.ComponentModel;

using System.Diagnostics;

using System.Web.Services;

using System.Web.Services.Protocols;

using System.Xml.Serialization;

using System.Xml;

using System.IO;



namespace WebserviceWrapper

{

public class Proxy

{

static XmlDocument XmlCacheIn = new XmlDocument();

static XmlDocument XmlCacheOut = new XmlDocument();

// Create a SoapExtensionAttribute for the SOAP Extension that can be

// applied to an XML Web service method.

[AttributeUsage(AttributeTargets.Method)]

public class ClientSideSoapExtensionAttribute : SoapExtensionAttribute

{

private string filename = "c:\\log.txt";

private int priority;

public override Type ExtensionType

{

get { return typeof(ClientSideSoapExtension); }

}

public override int Priority

{

get { return priority; }

set { priority = value; }

}

public string Filename

{

get

{

return filename;

}

set

{

filename = value;

}

}

}



public class ClientSideSoapExtension : SoapExtension

{

private bool outgoing = true;

private bool incoming = false;

private Stream outputStream;

private Stream chainedOutputStream;

private String filename;

private Stream httpInputStream;

private System.Xml.XmlDocument xmlDoc = new XmlDocument();

private System.Xml.XmlDocument xmlDocNew = new XmlDocument();

public System.Xml.XmlNode retNode;

public override object GetInitializer(LogicalMethodInfo methodInfo,
SoapExtensionAttribute attribute)

{

//return ((TraceExtensionAttribute)attribute).Filename;

return "C:\\test" + ".log";

}

// The SOAP extension was configured to run using a configuration file

// instead of an attribute applied to a specific XML Web service

// method.

public override object GetInitializer(Type WebServiceType)

{

// Return a file name to log the trace information to, based on the

// type.

return "C:\\" + WebServiceType.FullName + ".log";

}

// Receive the file name stored by GetInitializer and store it in a

// member variable for this specific instance.

public override void Initialize(object initializer)

{

filename = (string)initializer;

}







public override Stream ChainStream(Stream stream)

{

Stream result = stream;

if (this.outgoing)

{

this.outputStream = stream;

this.chainedOutputStream = new MemoryStream();

result = this.chainedOutputStream;

//this.outgoing = false;

}

if (this.incoming)

{

this.httpInputStream = stream;

result = this.httpInputStream;

//this.incoming = false;

}

return result;

}

public override void ProcessMessage(SoapMessage message)

{

switch (message.Stage)

{

case SoapMessageStage.BeforeSerialize:

break;

case SoapMessageStage.AfterSerialize:

{

if (this.outgoing)

{

// Get the XML string which goes into the SOAP body

String soapBodyString = getXMLFromCache();

// Create the SOAP Message

// It Comprises of a <soap:Element> that Enclosed a <soap:Body>.

// Pack the XML Document Inside the <soap:Body> Element

String xmlVersionString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";

String soapEnvelopeBeginString = "<soap:Envelope
xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">";

String soapBodyBeginString = "<soap:Body>";

String soapBodyEndString = "</soap:Body>";

String soapEnvelopeEndString = "</soap:Envelope>";

Stream appOutputStream = new MemoryStream();

StreamWriter soapMessageWriter = new StreamWriter

(appOutputStream);

soapMessageWriter.Write(xmlVersionString);

soapMessageWriter.Write(soapEnvelopeBeginString);

soapMessageWriter.Write(soapBodyBeginString);

//soapMessageWriter.Write(getXMLFromCache);

//soapMessageWriter.Write((System.Xml.XmlDocument)Ht tpContext.Current.Items["XmlMessageOut"]);

soapMessageWriter.Write(soapBodyString);

soapMessageWriter.Write(soapBodyEndString);

soapMessageWriter.Write(soapEnvelopeEndString);

soapMessageWriter.Flush();

appOutputStream.Flush();

appOutputStream.Position = 0;

StreamReader reader = new StreamReader(appOutputStream);

StreamWriter writer = new StreamWriter(this.outputStream);

writer.Write(reader.ReadToEnd());

writer.Flush();

appOutputStream.Close();

this.outgoing = false;

this.incoming = true;

}

break;

}

case SoapMessageStage.BeforeDeserialize:

{

// Retrieve the SOAP Message from the Input Stream

// Save the SOAP Message in Request-scope State Bag

if (this.incoming)

{

StreamReader soapMessageReader = new StreamReader

(this.httpInputStream);

string soapBodyString = soapMessageReader.ReadToEnd();

this.xmlDoc.LoadXml(soapBodyString);

//Extract the xml from the soap

this.retNode =
this.xmlDocNew.ImportNode(this.xmlDoc.SelectSingle Node("//WebService"),
true);

this.xmlDocNew.AppendChild(this.retNode);


XmlCacheIn = this.xmlDocNew;

}

this.incoming = true;

break;

}

case SoapMessageStage.AfterDeserialize:

break;

}

}

private String getXMLFromCache()

{

System.Xml.XmlDocument xmlDoc;

xmlDoc = (System.Xml.XmlDocument)XmlCacheOut;

StringWriter strWriter = new StringWriter();

XmlTextWriter xmlWriter = new XmlTextWriter(strWriter);

xmlWriter.Formatting = Formatting.None;

xmlDoc.WriteTo(xmlWriter);

xmlWriter.Flush();

strWriter.Flush();

return strWriter.ToString();

}

}

[System.CodeDom.Compiler.GeneratedCodeAttribute("ws dl", "1.0.3705.0")]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("c ode")]

[System.Web.Services.WebServiceBindingAttribute(Nam e =
"GetMessageInterfaceBinding", Namespace =
"tns:GetMessageInterfacePortType")]

public partial class GetMessageInterface :
System.Web.Services.Protocols.SoapHttpClientProtoc ol

{

/// <remarks/>

public GetMessageInterface()

{

this.Url = "Verified accesible url of the webservice.";

}

/// <remarks/>

[ClientSideSoapExtensionAttribute]

[System.Web.Services.Protocols.SoapDocumentMethodAt tribute("urn:oracle:processMessage",
Use = System.Web.Services.Description.SoapBindingUse.Lit eral, ParameterStyle
= System.Web.Services.Protocols.SoapParameterStyle.B are)]

public System.Xml.XmlDocument processMessage(System.Xml.XmlDocument xml)

{

XmlCacheOut = xml;

System.Xml.XmlDocument s;

try

{

object[] results = this.Invoke("processMessage", new object[] {

xml});

}

catch (Exception) // catches without assigning to a variable

{

}

s = (System.Xml.XmlDocument)XmlCacheIn;

return s;

}

}

}

}

**********************************





the code above fails at the the line:

this.retNode =
this.xmlDocNew.ImportNode(this.xmlDoc.SelectSingle Node("//WebService"),
true);



with error: canot import null node.

Can someone tell why this code is failing?





Many thanks in advance

JJ





All times are GMT. The time now is 10:32 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.