stack stack
stack stack

Reputation: 25

Why i can not call the web service in c#?

I'm new in c# and want too call the bank web service,in bank document write this:
call the BatchBillPaymentRequest method with ClientBatchBillPaymentRequestData object for input argumant :

BatchBillPaymentRequest(ClientBatchBillPaymentRequestData data)

for that purpose write this class:

class ClientBatchBillPaymentRequestData
    {
        public string CallbackUrl { get; set; }
        public string LoginAccount { get; set; }
        public int OrderId { get; set; }
        public string BillId { get; set; }
        public string PayId { get; set; }
        public string AdditionalData { get; set; }
    }


and write this code:

payment.BillService behzad=new BillService();
            ClientBatchBillPaymentRequestData datas = new ClientBatchBillPaymentRequestData();
            datas.BillId = "1233";
            datas.CallbackUrl = "google.com";
            datas.LoginAccount = "213214";
            datas.OrderId = 123;
            datas.PayId = "2131243";
            datas.AdditionalData = "23213";
            behzad.BatchBillPaymentRequest(datas);


but in this line:

behzad.BatchBillPaymentRequest(datas);


get this error:
Severity Code Description Project File Line Suppression State

Error   CS1503  Argument 1: cannot convert from 'ConsoleApplication1.ClientBatchBillPaymentRequestData' to 'ConsoleApplication1.payment.ClientBatchBillPaymentRequestData'  ConsoleApplication1 L:\TEMP\ConsoleApplication1\ConsoleApplication1\Program.cs  23  Active


what happen?how can i solve that problem?thanks. VS add this class too project:

public ClientBatchBillPaymentResponseData BatchBillPaymentRequest(ClientBatchBillPaymentRequestData requestData) {
            object[] results = this.Invoke("BatchBillPaymentRequest", new object[] {
                        requestData});
            return ((ClientBatchBillPaymentResponseData)(results[0]));
        }

Upvotes: 0

Views: 83

Answers (1)

Mauro
Mauro

Reputation: 4511

As per Adriano Repetti's comment - when you added the web service reference Visual Studio created a class for you to use - so change this code from this

payment.BillService behzad=new BillService();
ClientBatchBillPaymentRequestData datas = new ClientBatchBillPaymentRequestData();
datas.BillId = "1233";
datas.CallbackUrl = "google.com";
datas.LoginAccount = "213214";
datas.OrderId = 123;
datas.PayId = "2131243";
datas.AdditionalData = "23213";
behzad.BatchBillPaymentRequest(datas);

to this

payment.BillService behzad=new BillService();
var datas = new ConsoleApplication1.payment.ClientBatchBillPaymentRequestData();
datas.BillId = "1233";
datas.CallbackUrl = "google.com";
datas.LoginAccount = "213214";
datas.OrderId = 123;
datas.PayId = "2131243";
datas.AdditionalData = "23213";
behzad.BatchBillPaymentRequest(datas);

You can streamline this a little by doing this instead too

payment.BillService behzad=new BillService();
var datas = new ConsoleApplication1.payment.ClientBatchBillPaymentRequestData{
    BillId = "1233",
    CallbackUrl = "google.com",
    LoginAccount = "213214",
    OrderId = 123,
    PayId = "2131243",
    AdditionalData = "23213"
}
behzad.BatchBillPaymentRequest(datas);

You should also remove the ClientBatchBillPaymentRequestData class you created as its surplus to requirements.

For each of the Attributes in your object instantiation, highlight it and press CTRL-Space to get autocomplete to correctly case your parameter name.

If you don't know the structure of your Webservice call you can use Wizdler for Chrome https://chrome.google.com/webstore/detail/wizdler/oebpmncolmhiapingjaagmapififiakb?hl=en to find out what the packets should be .

Once you install it, enter the WSDL URL in chrome, click the wizdler button to the right of the address bar and select the method you want to call, this will let you see the parameters (including their names and casing).

https://forgetfulprogrammer.files.wordpress.com/2014/06/wizdler.png

Upvotes: 1

Related Questions