Creating SOAP message body - c#

I would like to know how to create SOAP message, body, and envelope in C#. Any help or links appreciated.
I need to send a SOAP attachment to a third party Web Service. I don't need WCF. I know how it works. My client needs SOAP with attachment.

Here's a really super-short intro how to do this:
1) Create a new project (any kind - console app, windows app, web app - whatever) - File > New > Project
2) In your Solution Explorer, right-click on References and choose Add Service Reference
3) In the dialog box that pops up, you need to enter two things:
your URL where the service lives (typically with a ?wsdl query string to grab the WSDL - the service description)
your namespace where the service classes will live - pick whatever suits you
Then click on Go - this will talk to that service and see what it has to offer
4) Now, that dialog box should update, and show you the service and its operations, as discovered by Visual Studio:
5) Click on OK and some code gets generated in the background
6) Now instantiate a client-side proxy in your code, and call a method on it:
That's all you have to do - everything else, all the messy details of creating a SOAP header and message body, can be happily left to the WCF runtime.
Now go learn WCF!

marc_s: learn SOAP with Attachments before recommending others to learn WCF. SwA is not supported by .Net so he's got to roll his own and that is the background for his question.

Check this link out http://www.xefteri.com/articles/show.cfm?id=15
It describes process for VS.NET, but in VS2010 it is same process. This was an easiest way.
However, if you can construct SOAP message (for example, if you read WSDL and can construct message without any issues or you used something like SOAP UI (http://www.soapui.org/) to generate few mock up messages and got an idea) then you can simply do POST to that URL like in this example http://www.808.dk/?code-csharp-httpwebrequest

Related

How to create a SOAP Request C#

I know there are thousands of step-by-step samples for consuming a SOAP project with C#.
Actually, I tried many of those but didn't really get to understand how it works, how were needed components built or how to integrate a certificate for a secure connection.
I would be really grateful if any of you guys have a magical resource, since I read somewhere I shouldn't do it this way or another, I really want to know this well.
Thank you,
Best regards.
It's really simple actually. Suppose you have a service at http://myhost.com/XService.svc - right click References in the solution explorer and choose "Add a service reference" (older versions of VS called it web reference/web service)
A wizard appears; pop your URL into it, set a few options and hit Go
You'll get a client class set created that references the service, with methods that take a set of typed parameters based on what the service said it wanted when VS queried its WSDL. You might use it like:
var c = new XServiceClient();
bool result = c.CreateNewPerson("John Smith", 30, "js#hotmail.com");
The service client handles all of the xml creation, tcp socket connection, data transmission etc necessary to pass those 3 values you sent, to the web service so that the relevant method is called, the response is returned etc

Web API to insert records

I am working on Taleo web API. I have an XML file with several records that I will have to insert into the Taleo system using its web API.
I have got the Taleo API guide from http://tbe.taleo.net/products/TBE_API_Guide.pdf.
For the first time, I am working on web API so I don't know where to start. Although the guide shows some examples using SOAP, I don't know how to make this request and retrieve the response using C# or VB.NET. I googled it but didn't get much information about it. If you share your ideas, I would really appreciate it.
From the PDF, it appears the WSDL for the service is at: http://tbe.taleo.net/wsdl/WebAPI.wsdl. In your C#/VB project, use the "Add Service Reference" option on the context menu and supply that URI to the WSDL. That will generate a proxy and many ancillary classes on which you can call whatever methods you need - the SOAP details are under the covers. You'll instantiate an instance of WebAPIClient and should see all the relevant methods there.
For example, in C# after creating a new Service Reference with (uninspired) namespace name of ServiceReference2, I can code the following (though I have no idea what it does!):
var x = new ServiceReference2.WebAPIClient(); // I suspect there's an overload expecting credentials
ServiceReference2.AccountBean y = x.getAccountById("bar", 0);
Exception handling is left to the reader :)

Connect to Unknown SOAP Web Service

I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP.
Login in to the server.
POST string data to server
Receive and display server response
Here's the tough part. I do not have access to the server, nor do I know where the .JWS file is located on the server. I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data.
I have tried accessing the web service via URL, but I keep getting this message:
Hi there, this is an AXIS service!
Perhaps there will be a form for
invoking the service here...
In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? Are web services accessible via URL?
Thank you
Use WCF, and generate client proxies to the web service using the svcutil.exe tool.
running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service e.g. like
BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
// 2 lines if you ran svcutil.exe directly on the web service URL
EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
// svcutil.exe created
client.SomeOperation(42); // call an SomeOperation of the web service
Thanks for everyone's help. Looking back on this question, I can see how severely confused I was. Here is the solution I followed.
Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following.
Boot up Visual Studio
On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog
In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl)
Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService)
Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. To access one of the services, all you need to do is create a new object from the class.
//Example
sampleService.ClassName test = new sampleService.ClassName();
test.displayName("Jack");
See http://msdn.microsoft.com/en-us/library/bb552364.aspx for a starting point

Accessing Salesforce Webservice API using C#

I havent worked with that Salesforce API before, so I am a bit stuck on how to connect to the salesforce service.
So far I understood that I have to generate a wsdl file for my account or rather the account of my customer (step 1). So far, so good.
But now the Quickstart (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_quickstart_steps.htm) says something about "Import the WSDL File into your development platform" (step 2).
How do I import a wsdl file into Visual Studio 2008? I cant find the "Add Web Reference" option which is mentioned in the quickstart.
And if I only need to use the WSDL, what use has the Salesforce Dotnet API package which can be downloaded from the salesforce website
(http://wiki.developerforce.com/index.php/Salesforce_Dotnet_API)?
Are there any gotchas I should watch out for when developing applications that use the salesforce API?
If you follow the directions in Binz' answer, you should be able to add a web service reference using Visual Studio.
The "Salesforce Dotnet API package" on the wiki site is not required to access the SalesForce API, it's just a library that tries to abstract it.
As far as gotchas and other things to know, I would recommend that you read chapter 6 of the Force.com Cookbook. You have to sign up for a force.com developer account (free). Most of the things you'll need to be aware of are covered in this chapter. Here are a few of them:
logging in / logging out - session
management
query / queryMore pattern (needed if
you're going to pull large sets of
data from SalesForce)
how to construct a wrapper class -
there is some sample vb.net code you
can download as well
One other thing to note, if you're going to use SOQL to query your SalesForce data, and you need to filter on a SalesForce date field, you'll need to format the date string. Here's one way to do it:
public static string FormatDateForQuery(DateTime dateToFormat, bool includeTime)
{
if (includeTime)
{
return dateToFormat.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss+00:00");
}
else
{
return dateToFormat.ToUniversalTime().ToString("yyyy-MM-dd");
}
}
For Visual Studio 2008 you need to select 'Add Service Reference', then click the 'Advanced' button on the bottom left of the dialogue. There should then be a button on the bottom of that dialogue that says 'Add Web Reference'. You should be able to then select your wsdl file and a service client proxy will be auto genned for you by VS.
To create the WSDL file, go to (your name, top right), set up, develop > api > generate enterprise wsdl > generate. In Chrome, click save page as and put that file in the c drive. In Visual Studio, go to add service reference > advanced > add web reference. Point to the file you downloaded: file:///c:/wsdl.jsp.xml
There is a parsing issue when using .NET 2.0 with date time fields in salesforce, accessing through web services.
It seems to be a bug in .NET but there's another way to address it by manually editing the wsdl.
More information here:
http://community.salesforce.com/t5/NET-Development/Can-t-update-date-datetime-from-c-webservice-through-enterprise/m-p/96046

C# SOAP with a custom URL

Okay, simple situation: I'm writing a simple console application which connects to a SOAP web service. I've imported a SOAP Service reference and as a result, my application has a default endpoint build into it's app.config file.
The web service, however, can run on multiple servers and the URL to the proper web service is passed through the commandline parameters of my application. I can read the URL, but how do I connect the web service to this custom URL?
(It should be very simple, in my opinion. It's something I'm overlooking.)
Is this using an auto-generated class deriving from SoapHttpClientProtocol? If so, just set the Url property when you create an instance of the class.
Well, .NET can provide some very useless error messages sometimes. In IIS, the service was configured to AutoDetect cookieless mode. As a result, I had to append "?AspxAutoDetectCookieSupport=1" to the URL. Although that would fix the problem, it was just easier to go to the IIS console, open the properties of the service, go to the ASP.NET tab page, click the "Edit configuration" button, to to "State Management" in the newly popped up screen and change "Cookieless mode" into something other than "AutoDetect"...
Excuse me. Dumb error. Am going to hit myself on the head a few times for this. ;-)
As Jon said, you set the Url, as in:
Namespace.ClassName nwe = new Namespace.ClassName();
nwe.Url = "http://localhost/MyURL/site.asmx";

Categories