Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-07
5
Medium Priority
?
22,794 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
Didier Vally earned 1000 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 1000 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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

688 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