Quantcast
Channel: WCF, ASMX and other Web Services
Viewing all articles
Browse latest Browse all 555

The remote server returned an error: (415) Unsupported Media Type.

$
0
0

Dear all,

I am developing a wcf service which will send XML to a service outside my office.
Following is my code


Dim xml As String
xml = "http://send/p1/?xml=<?xml version=""1.0"" encoding=""utf-8""?>" +
"<Emp ID=""1234"">" +
"<EmpDtls>" +
"<Empno>" & Empno & "</empno>" +
"</EmpDtls>" +
"</Emp>"
Dim url As String = "http://send/p1"
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim requestBytes As Byte() = System.Text.Encoding.ASCII.GetBytes(xml)
req.Method = "POST"
req.ContentType = "text/xml;charset=utf-8"
req.ContentLength = requestBytes.Length
Dim requestStream As Stream = req.GetRequestStream()
requestStream.Write(requestBytes, 0, requestBytes.Length)
requestStream.Close()
Dim res As HttpWebResponse = DirectCast(req.GetResponse(), HttpWebResponse)
If res.StatusCode = HttpStatusCode.OK Then

End If
Dim sr As New StreamReader(res.GetResponseStream(), System.Text.Encoding.[Default])
Dim backstr As String = sr.ReadToEnd()
sr.Close()
res.Close()

I am getting following error message. Please help me to rectify this issue.
The remote server returned an error: (415) Unsupported Media Type.

Web.config
<system.net>
<defaultProxy>
<proxy usesystemdefault="False"/>
</defaultProxy>
</system.net>

<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>

Thanks
nick


Viewing all articles
Browse latest Browse all 555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>