I have to use provided Java web service. But the problem is custom HTTPHeaders are required by this service. I have searched for solutions. I think that this one would work if I could add reference. But when I try to add reference to the service I get the following error:
There was an error downloading 'http://.....'. The request failed with HTTP status 400: Bad Request. Metadata contains a reference that cannot be resolved: 'http://......'. The remote server returned an unexpected response: (400) Bad Request. The remote server returned an error: (400) Bad Request. If the service is defined in the current solution, try building the solution and adding the service reference again.
I think security server doesn't let me access to metadata. I have tried this solution provided at MSDN and added custom headers like below:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://....");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = string.Empty;
using (StreamReader contentReader = new StreamReader("D:\\test.txt"))
{
postData = contentReader.ReadToEnd();
}
//Add headers to request
request.Headers.Add("UserName", "myUserName");
request.Headers.Add("Password", "myPassword");
request.Headers.Add("SomeCustomHeader", "myCustomHeaderValue");
//string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "text/xml";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Display the status.
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd();
using (StreamWriter resultWriter = new StreamWriter("D:\\result.xml"))
{
resultWriter.Write(responseFromServer);
}
// Display the content.
//Console.WriteLine(responseFromServer);
// Clean up the streams.
reader.Close();
dataStream.Close();
response.Close();
Console.ReadLine();
and it worked for me. I can get result from service now (as xml files), and I also have WSDL. So I think I can parse this results to appropriate objects. But I want to be able to add service reference and use it like a normal service. I mean calling methods with their names, not using SOAP messages, and getting results as parsed objects. Is there any workaround? Thanks in advance.