function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Keyur PatelKeyur Patel 

How can we call Salesforce webservice in .Net C#?

Hello,

 

We are trying to dynamically invoke salesforce webservice without adding webreference in C#.Net. Our requirement is generate proxy based on salesforce wsdl and return method name, service name and out put automatically.

 

I am expecting same like in following URL : http://www.crowsprogramming.com/archives/66

 

We are passing following web request in c#. Net code.
====================================================
HttpWebRequest client = (HttpWebRequest)HttpWebRequest.Create("https://servername/services/wsdl/class/WebServiceName" + "?wsdl");
client.Credentials = new NetworkCredential("xyz@company.com", "test1uHN46qCxXomWqfRcEupLW9cg");
client.Method = "POST";

//client.ContentType = "application/x-www-form-urlencoded";
client.Headers.Add("Authorization" , "Basic " + loginResult.sessionId);
client.Headers.Add("SOAPAction", "");
client.ContentType = "text/xml;charset=\"utf-8\"";

HttpWebResponse wres = (HttpWebResponse)client.GetResponse();
XmlTextReader xmlreader = new XmlTextReader(wres.GetResponseStream());
serviceDescription = ServiceDescription.Read(xmlreader);
====================================================
We are getting following errors.

 

An error has occurred while opening external DTD 'http://www.w3.org/TR/html4/loose.dtd': The remote server returned an error: (500) Internal Server Error."}

 

How can i resolve this error?

Sonam_SFDCSonam_SFDC

Hi,

 

A 500 server error usually means the webservice is not working correctly.

Please crosscheck to make sure you have wrtitten the webservice correctly and to get a better Idea on how to call SF webservices  - go through the following post:

http://shivasoft.in/blog/salesforce/consume-salesforce-web-service-in-c-net-application/

http://whiterabbitservices.com/2011/04/01/calling-a-custom-salesforce-apex-web-service-from-c/

 

Hope this helps!

 

 

Keyur PatelKeyur Patel

Hi,

 

Thanks for the quick reply. My Salesforce webservice is working fine with adding service reference in C#.Net. I am looking dynamic generate proxy without adding service reference and creatiing object of service. 

 

I am looking solution same like in following link.. 

 

http://www.crowsprogramming.com/archives/66

 

I tried with solution mentioned in above link but it is giving me A 500 internal server error. At present, when i run my service it is always redirect to login page , once i enter my credential after that it is redirect me to my service.

 

Is it possible to bypass my login page and directly run my service in browser?