Click here to Skip to main content
16,015,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
First I have built a client application.

I've added a service reference by using the wsdl link.

Now, how to create the object and send request ??

What I have tried:

I have to send a request to the wsdl from an WINDOWS CONSOLE APP using 2 strings as input

any help would be appreciated
Posted
Updated 13-Sep-17 21:51pm
v5

1 solution

if you added a service reference to the web service definition language file for the endpoint, visual studio will have generated a proxy with the name that you gave the reference, you can new that up in a using statement for instance.

so say you have your service hosted in a console app with one endpoint locally implementing IHWservice at http://localhost:3000

This way of providing a self host is the best way to work with and debug such and porting it to somewhere else is only a few steps

C#
[ServiceContract(Namespace = "http:://company.url/area/concern/year/month/day")]
public interface IHWService {
    [OperationContract]
    string GetMessage();
}

public class HelloWorldService : IHWService{
    public string GetMessage(){
         return "Hello";
    }
}

//... in other assembly, for development self host console application
class Program{
    static void Main(string[] args){
       using(var host = new ServiceHost(typeof(HelloWorldService))){
         host.Open();
            Console.ReadLine();
        }
    }
}

To get that working, your config file of that host will specify something like
<system.serviceModel>
    <services>
        <service name="HWService" behviourConfiguration="yourservicebehaviour">
            <endpoint address="" contrac="IHWService" binding="basicHttpVinding" />
            <host>
                <baseAddresses>
                    <add baseAddress="http://localhost:3000/" />
    // ...


Now newing up the proxy and using it is as simple as

using(var proxy = new HWService.WhatYouCalledYourReferenceClient()){
     Console.WriteLine(proxy.GetMessage());
}


of cause your config of that place needs to have it's version of system.servicemodel thingies abc (Address, Binding, Configuration) to mirror the host.
 
Share this answer
 
Comments
Kingshuk_SP 19-Sep-17 0:59am    
Hi Thomas..

I don't have hosted in any console. The requirement won't allow me to host..

I have a wsdl file in a folder.

I have added the reference of that wsdl by the path where it located.
now I've added reference using the local path..

(E:\some folder\some folder\filename.wsdl)
after adding reference, i did following...

using WSDLCall.ServiceReference1;

ServiceReference1.GetCustomerData custInfo = new GetCustomerData();

----------after this i need help...

here if i go to definition of GetCustomerData() i can see...

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.7.9.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://someurl" +
"gement/v1")]
public partial class GetCustomerData : object, System.ComponentModel.INotifyPropertyChanged {

private CustID custAccIDField;

private OtherOrgId1 idField;

/// <remarks>
[System.Xml.Serialization.XmlElementAttribute(Order=0)]
public CustID custAccID {
get {
return this.custAccIDField;
}
set {
this.custAccIDField = value;
this.PropertyChanged("custAccID");
}
}

/// <remarks>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public OtherOrgId1 id {
get {
return this.idField;
}
set {
this.idField = value;
this.PropertyChanged("id");
}
}

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

protected void PropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}


----------------------
here the input should be "Id" and "custAccID"
Thomas Nielsen - getCore 19-Sep-17 3:34am    
self hosting is for development purpose, the only situation where that is not possible is if the service isn't your own :)
Anyway it looks like you successfully generate a proxy, the 'phone home' code. Now you have to focus on where is your endpoint and configuring that so that you can point your 'phone' at some number e.g. IP or other host identification and what port that is accepting you.
Very frequently you'll have to log in to get some sort of token which you can then use to query with. in your case it could look like you have to know what customer you're looking for first and your semantics don't appear valid i'd change what you wrote to
(any WHY oh why do you have a ServiceReference1 reference ?!! imo always give variables meaningfull names but that's a different story ;) )

using (var proxy = new WSDLCall.ServiceReference1.ServiceReference1Client()){
ServiceReference1.GetCustomerData custInfo = proxy.GetCustomerData();
//why doesn't call above take a parameter? doesn't make much sense without
}
Kingshuk_SP 19-Sep-17 4:11am    
ok now i understand better.
You know, why I was asking like that. Actually, if we create a demo wcf service like this:

public class Service1 : IService1
{
public string GetData(int value)
{
return string.Format("You entered: {0}", value);
}
}

and after this simply run it..... then if we create any client application like below:

using WSDLCall.DemoWCFService;

namespace WSDLCall
{
public partial class CallMethods : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Service1Client obj = new Service1Client();
lblData.Text = obj.GetData(2);
}
}
}

we can easily access like this right... so, we don't need to specify any endpoint.

but in WSDL file, you will only have classes, not this kind of methods.
That's the reason I was confused in the way to call.

and "ServiceReference1" was just for example.. in my project, i'll definitely use meaningful name.. :) :)
Thomas Nielsen - getCore 19-Sep-17 7:53am    
You will not in fact be sending any request to the wsdl. WSDL is short for Web Service Definition Language, is is equivalent to an xml schema it just describes the operations the service is offering. The endpoint is typically same adress where you pulled the wsdl from just without part of the path

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900