Solved

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

Posted on 2008-10-07
5
22,181 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

803 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