Calling remote Web service from NAV with .Net Interop Error
kopija
Member Posts: 4
Hi all,
I have a problem with calling remote Web service from NAV with dotNet interop variables.
I have created local web service that has only one action (HelloWorld).
The following is a sample SOAP 1.1 request and response:
The code that I have written:
On line
I get the following error: A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (415) Unsupported Media Type.
What am I doing wrong?
Kopija
I have a problem with calling remote Web service from NAV with dotNet interop variables.
I have created local web service that has only one action (HelloWorld).
The following is a sample SOAP 1.1 request and response:
POST /SimpleWebService.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost/HelloWorld"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://localhost" />
</soap:Body>
</soap:Envelope>
The code that I have written:
dotNetXMLDoc := dotNetXMLDoc.XmlDocument();
dotNetHttpUtility := dotNetHttpUtility.HttpUtility();
XMLRequestString := '<?xml version="1.0" encoding="utf-8"?>';
XMLRequestString += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
XMLRequestString += ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"';
XMLRequestString += ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
XMLRequestString += ' <soap:Body>';
XMLRequestString += ' <HelloWorld xmlns="http://localhost" />';
XMLRequestString += ' </soap:Body>';
XMLRequestString += '</soap:Envelope>';
dotNetWebHeaders := dotNetWebHeaders.WebHeaderCollection();
dotNetHttpWebRequest := dotNetHttpWebRequest.CreateHttp('http://localhost/SimpleWebService.asmx');
dotNetHttpWebRequest.Method('POST');
dotNetHttpWebRequest.ContentType('text/xml');
dotNetHttpWebRequest.MediaType('text/xml');
dotNetWebHeaders.Add('SOAPAction','http://localhost/HelloWorld');
dotNetHttpWebRequest.Headers(dotNetWebHeaders);
dotNetHttpWebRequest.ReadWriteTimeout(30);
dotNetStreamOut := dotNetStreamOut.MemoryStream();
dotNetStreamOut := dotNetHttpWebRequest.GetRequestStream;
dotNetStreamWriter := dotNetStreamWriter.StreamWriter(dotNetStreamOut);
dotNetStreamWriter.Write(XMLRequestString);
dotNetStreamWriter.Close();
dotNetWebResponse := dotNetHttpWebRequest.GetResponse;
dotNetStreamIn := dotNetWebResponse.GetResponseStream;
dotNetStreamReader := dotNetStreamReader.StreamReader(dotNetStreamIn);
dotNetXMLDoc.LoadXml(dotNetStreamReader.ReadToEnd());
MESSAGE(dotNetXMLDoc.OuterXml);
On line
dotNetWebResponse := dotNetHttpWebRequest.GetResponse;
I get the following error: A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (415) Unsupported Media Type.
What am I doing wrong?
Kopija
0
Comments
-
This issue has been resolved so I will post the solution for archive

The problem occured because setting the WebHeaderCollection to the HttpWebRequest removed all previously set headers.
So the "solution" was to set additional headers before setting the ContentType:dotNetWebHeaders.Add('SOAPAction','http://localhost/HelloWorld'); dotNetHttpWebRequest.Headers(dotNetWebHeaders); dotNetHttpWebRequest.ContentType('text/xml'); dotNetHttpWebRequest.MediaType('text/xml');0 -
I have an issue with Web service NAV with dotNet interop.
I do not know how manage the error with HttpWebRequest.GetResponse sentence. In my environment I have two databases that communicate each other using a web services. If I try to post some document and my web service return an error I want to manage this error and show it to the user but HttpWebRequest.GetResponse sentence return an internal error 500.
Anybody knows how manage it?
Thanks in advance.0 -
I have tried with above code but I am getting following error
A call to System.Net.HttpWebRequest.GetResponse failed with this message: The remote server returned an error: (500) Internal Server Error
is there any thing where i have to change in the above code thanks in advance0 -
Hi smshyd, im getting the same response . may i know in the end how did you resolve that error.
Regards
Mouli0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions