Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 22985
  • Last Modified:

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

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
kevinvw1
Asked:
kevinvw1
  • 2
  • 2
2 Solutions
 
Didier VallySystems Engineer and Finance AnalystCommented:
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
 
lucky_jamesCommented:
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
 
kevinvw1Author Commented:
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
 
lucky_jamesCommented:
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
 
kevinvw1Author Commented:
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now