Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
string soapResult;
using (WebResponse webResponse = webRequest.GetResponse())
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
Console.Write(soapResult);
}



using (WebResponse webResponse = webRequest.GetResponse())

heare i am getting ,the remote server returned an error 405 method not allowed

What I have tried:

string soapResult;
using (WebResponse webResponse = webRequest.GetResponse())
{
using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
{
soapResult = rd.ReadToEnd();
}
Console.Write(soapResult);
}
Posted
Updated 12-Aug-16 0:54am

1 solution

The error basically means that the method you are using "GET", "POST", "PUT" etc is not allowed by the target system.

HTTP Error 405 Method not allowed Explained[^]

Consult the documentation for the target API to see what kind of methods it supports and change your code accordingly.
 
Share this answer
 
Comments
Member 11920338 22-Aug-16 2:01am    
I asked them but they are saying we are not generated that service that is generated by system (PI system)

Clearly this is my problem...


favorite
1)my application is windows application (RFID application)

Present we are sending data to oracle,they are asked to change from oracle to SAP

2) For that purpose they are given SOAP web service we need to send parameters through url i googled and i found some code but it is not triggering to that url.

3) I tried with SOAP UI data send's successfully but using application data is not triggered.

Please give solution for this......
Member 11920338 22-Aug-16 2:02am    
and i tired this code

private void button1_Click(object sender, EventArgs e)
{
var url = "http://iltdpodev.itc.in:50000/dir/wsdl?p=ic/de7a99a9145f31eb931f8792ad1b7d51";
var action = "http://sap.com/xi/WebService/soap1.1";

var soapEnvelopeXml = CreateSoapEnvelope();
var soapRequest = CreateSoapRequest(url, action);
InsertSoapEnvelopeIntoSoapRequest(soapEnvelopeXml, soapRequest);

using (var stringWriter = new System.IO.StringWriter())
{
using (var xmlWriter = System.Xml.XmlWriter.Create(stringWriter))
{
soapEnvelopeXml.WriteTo(xmlWriter);
xmlWriter.Flush();
}
}

}
private static System.Net.HttpWebRequest CreateSoapRequest(string url, string action)
{
var webRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
System.Net.NetworkCredential credential = new System.Net.NetworkCredential("", "");
webRequest.Credentials = credential;
webRequest.KeepAlive = true;
webRequest.UseDefaultCredentials = true;
return webRequest;
}

private static System.Xml.XmlDocument CreateSoapEnvelope()
{
string s1 = " <soapenv:envelope xmlns:soapenv="\"http://schemas.xmlsoap.org/soap/envelope/\"" xmlns:fus="\"http://FUSION_PP_RFID_I_PP3_001_RFIDMARRYINGWITHUBC\""> "
+ " <soapenv:header> "
+ " <soapenv:body> "
+ " <fus:mt_rfid_data_sender> "
+ " <rfid_data> "
+ " <![CDATA[<rfid_tag_no>501]]> "
+ " <![CDATA[<feeding_line_number>502]]> "
+ " <![CDATA[<step_number>503]]> "
+ "<![CDATA[<ubc_number>504]]> "
+ " <![CDATA[<status>505]]> "
+ " "
+ " "
+ " "
+ " ";

string s2 = " <soapenv:envelope xmlns:soapenv="\"http://schemas.xmlsoap.org/soap/envelope/\"" xmlns:fus="\"http://FUSION_PP_RFID_I_PP3_001_RFIDMARRYINGWITHUBC\""> "
+ " <soapenv:header> "
+ " <soapenv:body> "
+ " <fus:mt_rfid_data_sender> "
+ " <rfid_data> "
+ " <rfid_tag_no>501 "
+ " <feeding_line_number>502 "
+ " <step_number>503 "
+ " <ubc_number>504 "
+ " <status>505 "
+ " "
+ " "
+ " "
+ " ";



var soapEnvelope = new System.Xml.XmlDocument();
soapEnvelope.LoadXml(s1); //the SOAP envelope to send
return soapEnvelope;
}

private static void InsertSoapEnvelopeIntoSoapRequest(System.Xml.XmlDocument soapEnvelopeXml, System.Net.HttpWebRequest webRequest)
{
using (System.IO.Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);

}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900