views:

771

answers:

5

I have to connect to a third party web service that provides no wsdl nor asmx. The url of the service is just http://server/service.soap

I have read this article about raw services calls, but I'm not sure if this is what I'm looking for.

Also, I've asked for wsdl files, but being told that there are none (and there won't be).

I'm using C# with .net 2.0, and can't upgrade to 3.5 (so no WCF yet). I think that third party is using java, as that's the example they have supplied.

Thanks in advance!

UPDATE Get this response when browsing the url:

<SOAP-ENV:Envelope>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>
Cannot find a Body tag in the enveloppe
</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
A: 

Add it over VisualStudio as Web Reference.

But note - that studio will update this each time project opens. That is why my favorite way - to create this web reference and after it include generated files as regular .cs (obviously don't forget to exclude web reference).

Dewfy
I should have said that I've already tried this, with no luck. VisualStudio does not recognice the url of the web service as a valid document. I'll try to put the error message later, as i'm currently using spanish version of vs.
MaLKaV_eS
are you sure that service exists at specified address? can you browse it? May be this is not SOAP (but native format over XML)
Dewfy
Yes, I get a soap response when I tried to navigate to the service URL.
MaLKaV_eS
-1: He said there is no WSDL.
John Saunders
+1  A: 

If you're lucky you could still get the wsdl. Some web service frameworks allow you to retrieve a dynamically generated WSDL.

Web Services written with Axis1.x allow you to retrieve a dynamically generated WSDL file by browsing to the URL.

Just browse to

http://server/service.soap/?wsdl

I don't know if this is possible with other frameworks though.

Glen
Tried this, didn't work. Thanks anyway :)
MaLKaV_eS
thought it was a bit of a long shot. Do you know that framework (if any) the service is written in? If there is no WSDL then how are you supposed to use this service? Do they have any guidelines for you?
Glen
They have submited some .java files as example, but as I do know nothing of Java...
MaLKaV_eS
+1  A: 

Hmm, tricky one here but not impossible but I'll do my best to explian it.

What you'll need to do is

  1. Create serializable classes that match the object schemas you're dealing with on the third party service.
  2. Find out if they use any SOAPAction in their service calls
  3. See if you can create an asmx which mimics their service in terms of being able to handle requests and responses (this will be good for testing your client app if their service is down)
  4. You can then create a service proxy from your dummy service and change the service url when calling the third party service.
  5. If something doesnt work in your client, then you can tweak your dummy service, re-generate the proxy and try again.

I will try to add more as and when I think of it but that should be enough to get you started.

Keith
I'll look for information about this, but please, post any information you think is usefull.
MaLKaV_eS
Yeah, hope they even have XML schema for this. OTOH, if you're going to do anything with a dummy service, don't do anything with ASMX - use WCF instead.
John Saunders
Is WCF compatible with 2.0? I think it could only be used with 3.0
MaLKaV_eS
Sorry, forgot you're stuck in the ancient past. You have to use ASMX, even if Microsoft is no longer fixing bugs in it.
John Saunders
A: 

In my opinion, there is no excuse for a SOAP web service to not supply a WSDL. It need not be dynamically generated by the service; it need not be available over the Internet. But there must be a WSDL, even if they have to send it to you on a floppy disk!

Is this service from some government organization, university or other non-profit organization? I only just the other day learned of one, http://www.3gpp.org/, where they publicly state that a WSDL is something they might get around to one day. This is a professional telecom organization, and I can just barely excuse them, but only by thinking unpleasant thoughts about "telecoms guys".

If you have any ability to complain to the providers of this service, then I urge you to do so. If you have the ability to push back, then do so. Ideally, switch service providers, and tell these people it's because they didn't provide a WSDL.

At the very least, find out why they don't think it's important. I'm personally coming to the conclusion that people who don't think WSDL is important are those who weren't going to use one anyway - those who do not have access to tools that will generate code based on a WSDL.

Other than that, I have a very hard time thinking why any organization that offers a SOAP web service wouldn't have a WSDL, considering how long the standard has been out there, and how long tools have been available to create them!

Do they at least provide XML schemas that document the XML they send?

John Saunders
The XML scheme to send and retrieve information are documented. The only thing I lack is the knowledge to connect to it properly.As for the company providing it, is an insurance company, so no possibility to complain :(
MaLKaV_eS
Actually, I strongly disagree with that. Are these schemas part of any industry-standard, from an industry standards organization (international or not). If so, this gives you a single point to press on, and an industry full of other developers who could join with you in pushing. It's not like you're asking them to do something very complicated or expensive, especially if they already have a mechanism for distributing the schemas. Even if it's specific to the company, once they've got the schemas, the rest is pretty easy.
John Saunders
Any luck finding out why they don't want to provide a WSDL? Maybe you should get a trial of XMLspy, and show them how easy it would be, since they've already got the XML schemas.
John Saunders
+1  A: 

Well, finally I get this to work, so I'll write here the code I'm using. (Remember, .Net 2.0, and no wsdl to get from web service).

First, we create an HttpWebRequest:

public static HttpWebRequest CreateWebRequest(string url)
{
    HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
    webRequest.Headers.Add("SOAP:Action");
    webRequest.ContentType = "text/xml;charset=\"utf-8\"";
    webRequest.Accept = "text/xml";
    webRequest.Method = "POST";
    return webRequest;
}

Nest, we make a call to the webservice, passing along all values needed. As I'm reading the soap envelope from a xml document, I'll handle the data as a StringDictionary. Should be a better way to do this, but I'll think about this later:

public static XmlDocument ServiceCall(string url, int service, StringDictionary data)
{
    HttpWebRequest request = CreateWebRequest(url);

    XmlDocument soapEnvelopeXml = GetSoapXml(service, data);

    using (Stream stream = request.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }

    IAsyncResult asyncResult = request.BeginGetResponse(null, null);

    asyncResult.AsyncWaitHandle.WaitOne();

    string soapResult;
    using (WebResponse webResponse = request.EndGetResponse(asyncResult))
    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
    {
        soapResult = rd.ReadToEnd();
    }

    File.WriteAllText(HttpContext.Current.Server.MapPath("/servicios/" + DateTime.Now.Ticks.ToString() + "assor_r" + service.ToString() + ".xml"), soapResult);

    XmlDocument resp = new XmlDocument();

    resp.LoadXml(soapResult);

    return resp;
}

So, that's all. If anybody thinks that GetSoapXml must be added to the answer, I'll write it down. Thanks for the help!

MaLKaV_eS