Can i use c# with apigee

Not applicable

I want to use apigee but as i see i cant use soap wsdl with c#. In normal We do , add service reference and write wsdl url. Then we can use service. But in apigee i create api proxy and i get a link but i paste it add service reference page but it cant find. Firs question Can i use apigee with c#. Second one how? 🙂

0 11 6,129
11 REPLIES 11

msebai
Participant II

@Soner Canoğlu I assume you're trying to expose existing SOAP service via Edge, pls check documentation. If you configured your proxy as pass through, you should be able to use the same WSDL - its only the location of your soap address that will change, in this case should be Apigee Edge proxy URL.

Hope this helps

As you say i read the document. But it doesnt contain any example for soap. It explains something as a theory. I did what it writes but i cant get any link with wsdl. There is a link http://xx.xx.xx.xx:9002/exampleservice. when i write it to addressbar i get an error; {"fault":{"faultstring":"Raising fault. Fault name : validate-content-type","detail":{"errorcode":"messaging.runtime.RaiseFault"}}}.

Please help me.

Sounds like HTTP content type error, your proxy expects xml payload. I'm happy to jump on a call to discuss, just sent you an email.

if you know write from here and everybody learns

@Soner Canoğlu you need to provide further details (ideally proxy bundle, WSDL etc) in order for anyone to help. Like I said, the error above is likely because the proxy expects XML payload. Using browser to invoke the service will not set the right content type hence the error. Use Postman or other tool to invoke the service with valid SOAP request

Not applicable

For an example I use "http://www.w3schools.com/xml/tempconvert.asmx?wsdl". I create a api proxy and i choose proxy type as a "Pass-Through SOAP".

Then i get a link "http://xx.xx.x.x:9002/tempconvert". My problem is how can i call this service now? What must i do?

When i paste this link to postman, i got this error. "{"fault":{"faultstring":"Raising fault. Fault name : validate-content-type","detail":{"errorcode":"messaging.runtime.RaiseFault"}}}" and "415 Unsupported media type. Expecting the request header Content-Type to be 'text/xml' or 'application/json"

And how can i call this service with c#.net

msebai
Participant II

The error indicates that you're not using the correct HTTP content type. In your case it has to be set to "text/xml".

I used the same service you referred to and configured pass-through SOAP proxy on Edge. I can successfully invoke CelsiusToFahrenheit operation using Postman. Make sure to:

1. Set "Content-Type" header to "text/xml"

2. Provide valid SOAP request in the body e.g.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:x="http://www.w3schools.com/xml/">
   <soapenv:Header/>
   <soapenv:Body>
      <x:CelsiusToFahrenheit>
         <x:Celsius>15</x:Celsius>
      </x:CelsiusToFahrenheit>
   </soapenv:Body>
</soapenv:Envelope>

You can test my proxy using cURL:

curl -X POST -H "Content-Type: text/xml" -d '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:x="http://www.w3schools.com/xml/">
   <soapenv:Header/>
   <soapenv:Body>
      <x:CelsiusToFahrenheit>
         <x:Celsius>15</x:Celsius>
      </x:CelsiusToFahrenheit>
   </soapenv:Body>
</soapenv:Envelope>' "http://msebai-test.apigee.net/v1/temp/celsiustofahrenheit"

Not sure how to invoke SOAP service using C#, but you should be able to follow the same procedures that you'd normally do i.e. Apigee Edge acts as pass through proxy so you should 1) point your code to Apigee proxy URL, 2) set content type to text/xml and 3) provide valid SOAP request as provided above.

Can you explain with photos. Btep by step please. I couldnt do 😞

Try this C# code. Again, exposing the service via Apigee Edge does not change how you'd consume it using C# or any other language for that matter.

Be aware this code is not tested and provided only to get you started.

using System.Xml;
using System.Net;
using System.IO;
public static void CallWebService()
{
    var _url = "http://msebai-test.apigee.net/v1/temp/celsiustofahrenheit";
    XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
    HttpWebRequest webRequest = CreateWebRequest(_url);
    InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
    // begin async call to web request.
    IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
    // suspend this thread until call is complete. You might want to
    // do something usefull here like update your UI.
    asyncResult.AsyncWaitHandle.WaitOne();
    // get the response from the completed web request.
    string soapResult;
    using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
    {
        using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
        {
            soapResult = rd.ReadToEnd();
        }
        Console.Write(soapResult);        
    }
}
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 xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:x="http://www.w3schools.com/xml/"><soapenv:Header/><soapenv:Body><x:CelsiusToFahrenheit><x:Celsius>15</x:Celsius></x:CelsiusToFahrenheit></soapenv:Body></soapenv:Envelope>");
    return soapEnvelop;
}
private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
    using (Stream stream = webRequest.GetRequestStream())
    {
        soapEnvelopeXml.Save(stream);
    }
}

You can find more sources online.

Is there anyone knows how can i use it in c#

Not applicable

THANK YOU SO MUCH.... I have another question to you. This service has two method(FahrenheitToCelsius,CelsiusToFahrenheit). But I have service which has 10 methods. As far as i understand i must say everybody who will consume my service, all link and soap information.

For example:

Link 1 =>"http://msebai-test.apigee.net/v1/temp/celsiustofahrenheit"

Soap 1= > <soap .....

Link 2 => "http://msebai-test.apigee.net/v1/temp/xxxx"

Soap2=> <soap....

Link3 => "http://msebai-test.apigee.net/v1/temp/yyyyy"

Soap3=> <soap.....

It is true that I must give all this information?

If it is like this, It is very dificult.