Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Authentication of Web Services 3 49
Problem to error 4 44
Anyway to make "All" the default in the dropdown? 6 34
how to read json value 2 30
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 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

24 Experts available now in Live!

Get 1:1 Help Now