Hello friends,
I am developing a window application in C#.I want to consume the data from web service in my window application using soap and that web service is developed in PHP. So how can I do it?
Also, I want to ask that, Can I pass URL directly in code without adding web reference?
Loading
brinda lakhaniPosted Feb 12, 2015, 1:43 AM
keyurPosted Feb 12, 2015, 1:28 AM
If you have SOAP and wsdl you can follow below method to call service without adding ref
///
private XmlDocument CallWebService(string method, string operation, string xmlPayload)
{
string result = "";
string CREDENTIALS = "PASSword123";
string URL_ADDRESS = "http://www.client.com/_ws/" + method + "?sso=" + CREDENTIALS + "&o=" + operation +; //TODO: customize to your needs
// ===== You shoudn't need to edit the lines below =====
// Create the web request
HttpWebRequest request = WebRequest.Create(new Uri(URL_ADDRESS)) as HttpWebRequest;
// Set type to POST
request.Method = "POST";
request.ContentType = "application/xml";
// Create the data we want to send
StringBuilder data = new StringBuilder();
data.Append(xmlPayload);
byte[] byteData = Encoding.UTF8.GetBytes(data.ToString()); // Create a byte array of the data we want to send
request.ContentLength = byteData.Length; // Set the content length in the request headers
// Write data to request
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
// Get response and return it
XmlDocument xmlResult = new XmlDocument();
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
result = reader.ReadToEnd();
reader.Close();
}
xmlResult.LoadXml(result);
}
catch (Exception e)
{
xmlResult = CreateErrorXML(e.Message, ""); //TODO: returns an XML with the error message
}
return xmlResult;
}
Hope this method is useful.
brinda lakhaniPosted Feb 12, 2015, 1:26 AM
Piyush PansuriyaPosted Feb 12, 2015, 1:23 AM
http://www.codeproject.com/Articles/84345/Developing-SOAP-Web-Services-with-PHP-C
https://spring.io/guides/gs/consuming-web-service/
brinda lakhaniPosted Feb 12, 2015, 1:14 AM
Piyush PansuriyaPosted Feb 12, 2015, 1:10 AM
Right click on your project -> Add -> Service Reference
Now paste your URL into Address and click on GO.
You will get methods of your web services in Service: Box
Give Namespace to your reference and OK.
Now you can access this service in your project using namespace as you given.
brinda lakhaniPosted Feb 12, 2015, 1:04 AM
Piyush PansuriyaPosted Feb 12, 2015, 1:01 AM
Yes you can pass URL of web service. Or you can add service reference using URL of web service in your window application.