Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c# client program to invoke webservice is not working. 1

Status
Not open for further replies.

mh567

Programmer
May 15, 2007
7
US
Hi All,

I want to invoke/consume the webservice in C#.
I am using .NET Framework SDK on Windows 2000 professional.

I have webservice created in oracleJ developer. it returns group of record in XML format.

I followed steps from this link

and, I have return Client in c#. regarding this I created Proxy using Wsdl.exe then compiled it to get its .dll in the same folder. then in Client Program i created instance of this proxy class to get webservice output. my clinet code is like this
Code:
using System;
using System.IO;
class psdata
{
    public static void Main(string[] args)
    {
        //Create instace for proxy 
        EWebService epa = new EwebService();
        string iddata = epa.testWebserviceXML("hg");
       
        Console.WriteLine(iddata);
         
    }
}
it is giving me two errors:

Error 1: regarding converting XML to string.
which datatype i have to use to get XML output of webservice.

error 2: after removing 'String iddata' with 'system.xml.xmltype iddata' the program got compiled but runnin EXE just shows only 'system.xml.xmltype' line in Command line window.

How do i get the actual XML output of webservice and
How can i write this XML output in a saparate File?


Thank you
 
You actually want the XML in raw format? Normally SOAP converts the low level stuff to useable classes/data types.

If you have a method that returns an XmlDoc or a string of XML that would be easy.

While maybe not the most convenient way to consume a webservice, I tend to run the wsdl.exe to generate a class for me which provides all the methods for me.

Typically WSDL.exe can be found here:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin

I say typically, only because that's how it is on my computer :)

You would then use this class like a normal object.

If I've missed something tell me...
 
Yes, you are right i need xml output in Raw format from web service.

as you said having a method that returns an XmlDoc or a string of XML that would be easy.

for this i navigated yhis path
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\
as you suggested
but on my computer in this v2.0 folder no 'Bin' folder is there only 'Docs' folder is there.

I have installed .Net framework SDK on different folder from there i executed Wsdl.exe to create proxy class.

can you tell me detail or in steps how can i get this Raw xml output.


Thank you


 
I'm confused on why you need this raw xml. Can you clarify? There may be an easier way of implementing your solution.

 
Hi,

ok. on the other side i would also like to get data value from web service in stead of raw xml.

But how to get this? after running my simple client programe it returns only one line i.e.

'system.xml.xmltype'

as i mentioned my webservice is created using oracle Jdeveloper. and when i invoked it in Browser saparately for test it returned data values in raw XML format.
And that's why i thought that invoking this webservice from C# will also return Raw xml output.

any way if there is way of getting direct data values instead of Raw XML will Nice for me.

i have pasted my simple client code before this
Now this is the proxy created by wsdl.exe


Code:
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.42
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Serialization;

// 
// This source code was auto-generated by wsdl, Version=2.0.50727.42.
// 


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Web.Services.WebServiceBindingAttribute(Name="EpassWebServiceSoapHttp", Namespace="[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl")[/URL]]
public partial class EpassWebService : System.Web.Services.Protocols.SoapHttpClientProtocol {
    
    private System.Threading.SendOrPostCallback testWebserviceXMLOperationCompleted;
    
    private System.Threading.SendOrPostCallback testWebserviceXMLRowSetOperationCompleted;
    
    /// <remarks/>
    public EpassWebService() {
        this.Url = "[URL unfurl="true"]http://localhost/PL_SQL_WS-GetIdms-context-root/EpassWebServiceSoapHttp"[/URL] +
            "Port";
    }
    
    /// <remarks/>
    public event testWebserviceXMLCompletedEventHandler testWebserviceXMLCompleted;
    
    /// <remarks/>
    public event testWebserviceXMLRowSetCompletedEventHandler testWebserviceXMLRowSetCompleted;
    
    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/testWebserviceXML",[/URL] RequestElementName="testWebserviceXMLElement", RequestNamespace="[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/types/",[/URL] ResponseElementName="testWebserviceXMLResponseElement", ResponseNamespace="[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/types/",[/URL] Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("result", IsNullable=true)]
    public System.Xml.XmlElement testWebserviceXML([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string vTest) {
        object[] results = this.Invoke("testWebserviceXML", new object[] {
                    vTest});
        return ((System.Xml.XmlElement)(results[0]));
    }
    
    /// <remarks/>
    public System.IAsyncResult BegintestWebserviceXML(string vTest, System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("testWebserviceXML", new object[] {
                    vTest}, callback, asyncState);
    }
    
    /// <remarks/>
    public System.Xml.XmlElement EndtestWebserviceXML(System.IAsyncResult asyncResult) {
        object[] results = this.EndInvoke(asyncResult);
        return ((System.Xml.XmlElement)(results[0]));
    }
    
    /// <remarks/>
    public void testWebserviceXMLAsync(string vTest) {
        this.testWebserviceXMLAsync(vTest, null);
    }
    
    /// <remarks/>
    public void testWebserviceXMLAsync(string vTest, object userState) {
        if ((this.testWebserviceXMLOperationCompleted == null)) {
            this.testWebserviceXMLOperationCompleted = new System.Threading.SendOrPostCallback(this.OntestWebserviceXMLOperationCompleted);
        }
        this.InvokeAsync("testWebserviceXML", new object[] {
                    vTest}, this.testWebserviceXMLOperationCompleted, userState);
    }
    
    private void OntestWebserviceXMLOperationCompleted(object arg) {
        if ((this.testWebserviceXMLCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.testWebserviceXMLCompleted(this, new testWebserviceXMLCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }
    
    /// <remarks/>
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/testWebserviceXMLRowSet",[/URL] RequestElementName="testWebserviceXMLRowSetElement", RequestNamespace="[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/types/",[/URL] ResponseElementName="testWebserviceXMLRowSetResponseElement", ResponseNamespace="[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/types/",[/URL] Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("result", IsNullable=true)]
    public System.Xml.XmlElement testWebserviceXMLRowSet([System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] string vTest) {
        object[] results = this.Invoke("testWebserviceXMLRowSet", new object[] {
                    vTest});
        return ((System.Xml.XmlElement)(results[0]));
    }
    
    /// <remarks/>
    public System.IAsyncResult BegintestWebserviceXMLRowSet(string vTest, System.AsyncCallback callback, object asyncState) {
        return this.BeginInvoke("testWebserviceXMLRowSet", new object[] {
                    vTest}, callback, asyncState);
    }
    
    /// <remarks/>
    public System.Xml.XmlElement EndtestWebserviceXMLRowSet(System.IAsyncResult asyncResult) {
        object[] results = this.EndInvoke(asyncResult);
        return ((System.Xml.XmlElement)(results[0]));
    }
    
    /// <remarks/>
    public void testWebserviceXMLRowSetAsync(string vTest) {
        this.testWebserviceXMLRowSetAsync(vTest, null);
    }
    
    /// <remarks/>
    public void testWebserviceXMLRowSetAsync(string vTest, object userState) {
        if ((this.testWebserviceXMLRowSetOperationCompleted == null)) {
            this.testWebserviceXMLRowSetOperationCompleted = new System.Threading.SendOrPostCallback(this.OntestWebserviceXMLRowSetOperationCompleted);
        }
        this.InvokeAsync("testWebserviceXMLRowSet", new object[] {
                    vTest}, this.testWebserviceXMLRowSetOperationCompleted, userState);
    }
    
    private void OntestWebserviceXMLRowSetOperationCompleted(object arg) {
        if ((this.testWebserviceXMLRowSetCompleted != null)) {
            System.Web.Services.Protocols.InvokeCompletedEventArgs invokeArgs = ((System.Web.Services.Protocols.InvokeCompletedEventArgs)(arg));
            this.testWebserviceXMLRowSetCompleted(this, new testWebserviceXMLRowSetCompletedEventArgs(invokeArgs.Results, invokeArgs.Error, invokeArgs.Cancelled, invokeArgs.UserState));
        }
    }
    
    /// <remarks/>
    public new void CancelAsync(object userState) {
        base.CancelAsync(userState);
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void testWebserviceXMLCompletedEventHandler(object sender, testWebserviceXMLCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class testWebserviceXMLCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    
    private object[] results;
    
    internal testWebserviceXMLCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
            base(exception, cancelled, userState) {
        this.results = results;
    }
    
    /// <remarks/>
    public System.Xml.XmlElement Result {
        get {
            this.RaiseExceptionIfNecessary();
            return ((System.Xml.XmlElement)(this.results[0]));
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
public delegate void testWebserviceXMLRowSetCompletedEventHandler(object sender, testWebserviceXMLRowSetCompletedEventArgs e);

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class testWebserviceXMLRowSetCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
    
    private object[] results;
    
    internal testWebserviceXMLRowSetCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) : 
            base(exception, cancelled, userState) {
        this.results = results;
    }
    
    /// <remarks/>
    public System.Xml.XmlElement Result {
        get {
            this.RaiseExceptionIfNecessary();
            return ((System.Xml.XmlElement)(this.results[0]));
        }
    }
}

any suggestion to get right output from webservice.

Thank you
 
hi, i also followed your asigned website link


and i wrtoe program as below as instructed in above link, and tried to write code in all together:

I also placed my webservice soap env format in a file as per instruction from above link.

but i am getting
CS1518 Expected class, delegate, enum, interface, or struct
CS1022 Type or namespace definition, or end-of-file expected

Code:
static string _url = "[URL unfurl="true"]http://localhost/PL_SQL_WS-GetIdms-context-root/EpassWebServiceSoapHttpPort";[/URL] 
static string _action = "[URL unfurl="true"]http://dbconnection1/EpassWebService.wsdl/testWebserviceXML";[/URL] 
static string _inputPath = @"C:\csharp\v2.0\epassweb\soapenv.xml";
static string _outputPath = @"C:\csharp\v2.0\epassweb\xmloutput.xml"; 

static void Main(string[] args)    
{    
  string content = File.ReadAllText(_inputPath); 
 
// XmlDocument soapEnvelopeXml = CreateSoapEnvelope(content);

    StringBuilder sb = new StringBuilder(_soapEnvelope); 
    sb.Insert(sb.ToString().IndexOf(""), content);     

    // create an empty soap envelope      
 
   XmlDocument soapEnvelopeXml = new XmlDocument(); 
   soapEnvelopeXml.LoadXml(sb.ToString());
 
// return soapEnvelopeXml;


//HttpWebRequest webRequest = CreateWebRequest(_url, _action); 

HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);       
webRequest.Headers.Add("SOAPAction", action);        
webRequest.ContentType = "text/xml;charset=\"utf-8\"";       
webRequest.Accept = "text/xml";        
webRequest.Method = "POST";        

//return webRequest;
   
//InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest); 

 using (Stream stream = webRequest.GetRequestStream())        
{            
soapEnvelopeXml.Save(stream);        
}
   
// begin async call to web request.   

     IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); 

// suspend this thread until call is complete. You might want to      
// do something usefull here like update your UI. 

       asyncResult.AsyncWaitHandle.WaitOne();   
   
  // get the response from the completed web request.  
  
    string soapResult;       

 using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) 
 using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))   
    
    {        
    soapResult = rd.ReadToEnd();    
    }   

    File.WriteAllText(_outputPath, FormatDocument(soapResult)); 
}

any suggestions why these errors are coming.
aslo check action values from

webRequest.Headers.Add("SOAPAction", action);

i have used
which is namespace values from wsdl description of webservice. Actually in this wsdl description namespace tag values has only
but as per the website link instruction i added method in from tof it.

will it be correct? any suggestion to make it work?

Thank you
 
At this point it's a little beyond me unless I really sat down and played with it.

Anyone else have input?
 
ok. I will wait for your suggesions.

Thank you.
 
Hi.
Now as per this links steps

i have managed to create exe for my client programe....but after executing this exe i am getting this error.

Unhandled Exception: System.Net.WebException: The remote server returned an erro
r: (400) Bad Request.

does anybody knows about it?

I checked my soap envelope format 2-3 times but it is still coming?

on the other hand.
can anybody give me link or steps to create webservice which calls oracle stored procedure?


Thank you
 
can anybody give me link or steps to create webservice which calls oracle stored procedure?

in c#


Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top