Complex webservice scenario.

J

jens Jensen

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)HttpContext.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.SelectSingleNode("//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("wsdl", "1.0.3705.0")]

[System.Diagnostics.DebuggerStepThroughAttribute()]

[System.ComponentModel.DesignerCategoryAttribute("code")]

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

public partial class GetMessageInterface :
System.Web.Services.Protocols.SoapHttpClientProtocol

{

/// <remarks/>

public GetMessageInterface()

{

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

}

/// <remarks/>

[ClientSideSoapExtensionAttribute]

[System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:eek:racle:processMessage",
Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle
= System.Web.Services.Protocols.SoapParameterStyle.Bare)]

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.SelectSingleNode("//WebService"),
true);



with error: canot import null node.

Can someone tell why this code is failing?





Many thanks in advance

JJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,039
Messages
2,570,376
Members
47,026
Latest member
TishaMadri

Latest Threads

Top