Solved

how to call web service from C# .net windows app

Posted on 2008-10-07
5
22,008 Views
Last Modified: 2013-11-18
I have a c# windows form.  I have added a web reference to a web service running on another server on my network.
I have verified that the web service is responding by using VisualWebServiceClient  (VWSC)(http://digitforge.com/Public/Downloads.aspx) (great utilility by the way).

VWSC shows me the request that it sends to the web service as being -
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://strongmail.com/soap/strongmail.wsdl" xmlns:types="http://strongmail.com/soap/strongmail.wsdl/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body
        soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <execute>
            <smIn
                xsi:type="xsd:string">&lt;strongmail-client username="admin" password="admin"
 context="clientinfo" action="mailings"&gt;
&lt;mailing&gt;
&lt;status code="3"&gt;Active&lt;/status&gt;
&lt;/mailing&gt;
&lt;/strongmail-client&gt;</smIn>
        </execute>
    </soap:Body>
</soap:Envelope>
===================================================================

My questinon is how do I call the same web service and pass it the same info from inside a C# windows app?

I have the following lines of code -
====================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using StrongMailWebServicesTest1.StrongMail;
using System.Xml;

namespace StrongMailWebServicesTest1
{
    public partial class Form1 : Form
    {
        strongmail sm = new strongmail();

        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
           
            smIn = "&lt;strongmail-client username=&quot;admin&quot; password=&quot;admin&quot; context=&quot;clientinfo&quot; action=&quot;mailings&quot;&gt;&lt;mailing&gt;&lt;status code=&quot;3&quot;&gt;Active&lt;/status&gt;&lt;/mailing&gt;&lt;/strongmail-client&gt;";
            string smOut = "";            
            smOut = sm.execute(smIn);          
        }
    }
}
====================================================================

But I get a response back (smOut) telling me that there was an error parsing the input.

Thanks,

Kevin.

0
Comment
Question by:kevinvw1
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
Didier Vally earned 250 total points
ID: 22657224
If smOut gets a value, then its value has been set by a process inside the webservice.

I think then that smln has a wrong format.
0
 
LVL 7

Assisted Solution

by:lucky_james
lucky_james earned 250 total points
ID: 22657353
ppcdev, I checked smIn and it seems to be the same as what you are sending.

Kevin, Could you send us the stack trace or the exact error what you are getting out there.


regards,
James
0
 

Author Comment

by:kevinvw1
ID: 22662322
Amazing, just for the heck of it I tried passing un-encoded string to the web service.

I simply did this -
================================================================================
string smIn = "<strongmail-client username='admin' password='admin' context='clientinfo' action='mailings'> <mailing> <status code='3'>Active</status> </mailing> </strongmail-client>";

string smOut = "";            
smOut = sm.execute(smIn);          
================================================================================

and it worked perfectly!.

Any idea why this web service doesn't require encoding the string?
It is because I'm calling it from a windows .net app as opposed to an asp.net app ?

Thanks for your help.

Kevin.

0
 
LVL 7

Expert Comment

by:lucky_james
ID: 22665506
the only difference i can see here is the single quotes are used for the values instead of the double quotes!!......

try changing the quotes in this successful scenario from ' to "


James
0
 

Author Comment

by:kevinvw1
ID: 22665696
Hi Lucky_james, you can't use double quotes because they are within the string.

C# doesn't seem to like this either - string str = " username=""admin"" "

So for now the single quotes work and that is all I needed.

Thanks, Kevin.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now