How to implement SOAP communication for .net application - c#

I have to implement SOAP based communication between a .NET application and a local courier service. They have provided good documentation of their SOAP service with php samples and wsdl schema at http://www.rapido.bg/soap_help/, but I cannot find my way in implementing it for .NET with C#.
I looked at similar problems online and first tried to add the wsdl as Service reference which didn't create the necessary classes, then tried to add it as Web Reference, which generated the classes and methods, but could't generate some of the parameter types as expected. For example the login parameter was generated as string, whereas in the wsdl it is defined as xsd:struct and in the php sample its created and passed as an anonymous class with two fields.
I tried to implement the communication using web requests and building the SOAP messages manually following some other approaches, but still couldn't get it right.
It will be great if someone can get a simple app working or just let me know how to do it.
Thanks.

Try using WseWsdl2.exe, it will generate C# or VB.Net classes for you that can be used to communicate with the SOAP service of your choice.

Related

How to consume WCF service by dynamically creating client proxy

I was trying to generate proxy for a service using the code snippet mentioned here but I realized that the snippet is only for asmx services. Is there anyway to do the same for WCF services in c#?
Okay. After much searching found two classes which can do this for us along with help from others.
codecompiler
WSDLimporter
These two provide a way to download wsdl at runtime, extract contract and endpoint info and create code in C# or VB which can be compiled to create assembly on which reflection can be used to invoke WCF Service.
Hope this helps somebody someday!

Forbidden XML Schema constructs in WSDL of a web service

I am a Java developer who has created a rather big Web service that works nice with Java clients or other tools (Soap UI).
One of our clients wants to write a .NET client for the web service and uses the "add service reference" feature of VS2010. According to the client this does not work since our WSDL and XSD files use "Forbidden XML constructs" as defined in this article:
The problem is that we have made heavy usage of xsd:attribute data in WSDL.
So the question is:
Is there a workaround to make .NET stub generation code compliant with WSDL/XSD files that contain xsd:attribute? Is there another .NET library for webservices that supports this feature?
Another question of mine would be why does Microsoft impose these limitations in the first place? Why xsd:attribute is a forbidden costruct in a web service??? Any clues on that?
Probably related: C#.NET Generating web service reference using WSDL (from XML schema) problem
If you have access to a machine with the .NET Framework on it why don't you use svcutil to generate a proxy/config settings for him and send it to him?
See www.svcutil.com for the list of switches and options that are available to you
I have found that if the customer cannot do it one way and you provide a documented (possibly automated) way of doing things then that will generally suffice.
I have tested the HelloWorld.wsdl supplied in the link with the .NET version of Remobjects (http://www.remobjects.com) and it seemed to work fine. I don't have an actual service to test this with but I would suggest that you (or the client :) ) download it and give it a try.
The .NET version can be found here:
http://www.remobjects.com/ro/net.aspx
Apparently the answer is that you should NOT use the modern way of generating stubs with svcutil.exe and instead use the legacy way with wsdl.exe
Creating stubs from the command line with wsdl.exe works fine. The resulting code works as expected and the .NET client connects to the Axis2 Web service.

Web service written in both WCF and Java

Can I write a web service that implements the same methods and returns the same custom objects using both C#/WCF and also Java Web Services? And if so, can I then access the web services using a single web reference but with different addresses?
I'm asking because I have to host a web service that has a GetCitations and GetTerms method for publically exposing our database content. We are on IIS, so I was going to do it with WCF. However, other partners in the project also have to host an equivalent service and they are all Java based.
We are then building a software app that needs to connect to any number of these services (as defined at runtime by a user). I am expecting that we can have one set of classes to connect to these services (but with different endpoitn addresses), but am not sure whether I'm right in expecting this to work.
Is this possible?
And what considerations/restrictions are there?
Thanks.
It shouldn't be a problem, if you make sure that both services have equivalent wsdl files and you use http/soap binding.
I am not sure about using the binary (net.tcp) one with WCF, though. It might be a problem.
One way to do it is to use JAX-WS (Java 6) to expose a method as a web service.
The JAX-WS stack allows for automatically generating the correct WSDL at runtime.
The .NET team can then take that WSDL, and use standard tools to create a mock implementation of that WSDL. This mock implementation is then used as the actual .NET implementation, and you then use standard tools to generate the WSDL for that web service.
You now have to web services with the same semantics each with their own WSDL.
Both Java and .NET can implement a SOAP compliant web service, so the answer is yes, you can write a .NET and a Java webservice that implement the same WSDL.

C# web services: handling an object and methods in soap vs rest?

My understanding is that a c# based client "prefers" SOAP because when you add a web service reference it creates a proxy class from the wsdl found at the url you specify.
Which almost makes it transparent to the c# client that we are even using a web service, it almost feels like we are using a local class library. you call methods and you use objects.
My question is can REST achieve the same affect. I assume that it can't since it doesn't have wsdl and thus visual studio can't generate a proxy class for it. But Please correct me if I'm wrong?
A "run of the mill" REST service cannot achieve the same kind of tight integration with C# - mostly because it lacks the metadata that a SOAP service will provide (with a list of methods and their parameters and all that stuff).
The WCF Data Services (built on top of REST) do work much the same way as SOAP services, since the OData protocol contains extensions for pure REST services that provide metadata information needed to create a good, useful client-side proxy.
REST can be used to generate client side class libraries. For Example You can create proxy classes for MS generated REST services. In fact MS is actively pushing this model for Entity Framework based WCF DATA Services, e.g. those used by Silverlight and RIA applications. check out MS ODATA framework for REST which involves creating client objects out of standard REST queries.
http://msdn.microsoft.com/en-us/library/dd673930.aspx

Using WSDL for sending and receiving in C#

You are given a WSDL and a sample soap message, is there a good tutorial or sample code in using that WSDL to consume a web service? Does the WSDL follow a certain format in order for which it can be consumed properly? I recall a web service in Java that I changed certain tags and attributes in order for this to work, is there a general convention for the formatting used in WSDLs?
I think this might be harder than #1. You are given a WSDL and a sample soap message. Is there a way to use that given WSDL and not the WSDL generated by C# web service when exposing a web service? Is there a way to somehow "override" the WSDL of the web service to the given web service? Are there any conflicts in formatting and compatibility of the WSDL that ought to be considered?
The quickest and most painless approach is simply to use svcutil to generate the code representing the WSDL. At that point the code produced can be used as a client to query an existing service or you can define a class implemeting the service contact. Once you have the .NET classes the SOAP message example will just serve as documentation.
the default usage would be want you most likely want
svcutil myRemoteService.wsdl
which will generate a a file named [servicename].CS file and an output.config containing the necessary WCF client bindings.
Not sure what you mean by overriding the WSDL as it is the published contract that the service honors. So if you want to change method signatures or behavior it will no longer work as the change will no longer conform to the WSDL.

Categories

Resources