Call pass through to soap web service

Not applicable

When i use the following code (See below), i can get datas. But i don't want to include the soapenv:Envelope part in every method request.

Is there any way to call this service. For example

webrequest.Method = CelciusToFahrenit;

webrequest.Parameter = 10;

i want to write like this :):):)

protected void Page_Load(object sender, EventArgs e)
{
    var _url = "http://..../tempconvert-2/CelsiusToFahrenheit";
    XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
    HttpWebRequest webRequest = CreateWebRequest(_url); InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
    IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null); asyncResult.AsyncWaitHandle.WaitOne();
    string soapResult;
    using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
    {
        using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
        {
            soapResult = rd.ReadToEnd();
        }
    }
    private static HttpWebRequest CreateWebRequest(string url)
    {
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.ContentType = "text/xml";
        webRequest.Accept = "text/xml";
        webRequest.Method = "POST";
        return webRequest;
    }
    private static XmlDocument CreateSoapEnvelope()
    {
        XmlDocument soapEnvelop = new XmlDocument();
        soapEnvelop.LoadXml(@"<soapenv:Envelope ***********");
        return soapEnvelop;
    }
    private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
    {
        using (Stream stream = webRequest.GetRequestStream())
        {
            soapEnvelopeXml.Save(stream);
        }
    }
}


1 3 1,846
3 REPLIES 3

Yes, maybe.

The webRequest.method may accept only a limited set of values: "GET", "PUT", "POST", "DELETE" and a few others. "CelsiusToFahrenheit" is not one of them. So you cannot have that part.

However, You can simplify the request you need to make. Probably in your case it would be something like :

var targetUri = new Uri("https://soner-test.apigee.net/tempconvert/ctof/10");
var webRequest = (HttpWebRequest)WebRequest.Create(targetUri); 
var webRequestResponse = webRequest.GetResponse();

You will notice that I didn't specify the method at all. In C#, the above code implicitly uses a GET method. Also, I specified the "from" temperature as a path element. And the operation is also a path element (ctof => Celsius to Fahrenheit, ftoc = Fahrenheit to Celsius) .

Then, in the Apigee Edge environment, you can configure the proxy to inject the value "10" (or whatever you pass in the path element) into the appropriate Soap Envelope and send it to the existing back end. The backend sees a valid SOAP request, and your client app is much simpler.The backend sends a SOAP response, but Apigee Edge can simplify that as well.

We call this "SOAP to REST mediation", and it's a really common use of Apigee Edge.

If your backend is publicly available, I can even create the proxy for you that does all of this.

let me know if you want me to do that...

**Edit:

I found the w3schools.com WSDL that does temperature conversion. Using that WSDL, I produced an Apigee Edge proxy that does what you want. I can show you, if you like. let me know....

No it cant be like

var targetUri = new Uri("https://soner-test.apigee.net/tempconvert/ctof/10");
var webRequest = (HttpWebRequest)WebRequest.Create(targetUri); 
var webRequestResponse = webRequest.GetResponse();

because it is not a rest service. So it cant call like this.

I know the service(wsdl) you say. I say it in my question. I used it too.

When i use it as pass through soap, i must write soap envelope and other soap information. I asked that how can i call this service without writing soap envelope and other information.

I don't understand what you mean. It CAN BE just as I said. It is quite possible. In fact: I tried it, it works. To make that happen, you need a SOAP-to-REST proxy in Apigee Edge. Then your app calls the api proxy, and the apiproxy is the thing that builds the soap envelope and sends it to the temperature conversion service.

This avoids the need for you, as a client app developer, to produce a soap envelope and other soap information.

> I asked that how can i call this service without writing soap envelope and other information.

Yes, and I answered. To repeat: Create a SOAP-to-REST proxy, and call the proxy.

$ mono TestWebRequest.exe
result: 32
$ mono TestWebRequest.exe 10
result: 50
$ mono TestWebRequest.exe 40
result: 104

Actual code snip:

  var targetUri = new Uri("https://deecee-test.apigee.net/tempconvert/ctof/" +
                          tempToConvert);
  var webRequest = (HttpWebRequest)WebRequest.Create(targetUri);
  using (WebResponse webResponse = webRequest.GetResponse())
  {
      using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
      {
          var x = rd.ReadToEnd();
          Console.WriteLine("result: " + x);
      }
  }

The full source code for this program is here: TestWebRequest.cs

The full api proxy bundle is here: tempconvert.zip