skyzipper
asked on
Having problems creating WCF web service with Post command
Hello Experts,
This has been bother me for a couple days and I can't figure it out. I am trying to create a WCF Webservice with a Post command. This needs to except an xml as a parameter and return a string. When I run my service in the browser i get end point not found. When I run from a test application i get "The remote server returned an error: (404) Not Found." I am really not sure what I am doing wrong or how I should be calling this service. My code is below:
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.IO
' NOTE: You can use the "Rename" command on the context menu to change the interface name "IloginReq" in both code and config file together.
<ServiceContract()>
Public Interface IloginReq
<OperationContract(Name:=" PostSample Method")>
<WebInvoke(Method:="POST", UriTemplate:="PostSampleMe thod/[New] ", ResponseFormat:=WebMessage Format.Xml , RequestFormat:=WebMessageF ormat.Xml, BodyStyle:=WebMessageBodyS tyle.Bare) > _
Function PostSampleMethod(data As Stream) As String
End Interface
Imports System.Web.Script.Serializ ation
Imports System.IO
Imports System.Xml
<AspNetCompatibilityRequir ements(Req uirementsM ode:=AspNe tCompatibi lityRequir ementsMode .Allowed)> _
Public Class loginReq
Implements IloginReq
Public Function PostSampleMethod(data As Stream) As String Implements IloginReq.PostSampleMethod
' convert Stream Data to StreamReader
Dim reader As New StreamReader(data)
' Read StreamReader data as string
Dim xmlString As String = reader.ReadToEnd()
Dim returnValue As String = xmlString
' return the XMLString data
Return returnValue
End Function
End Class
'''Web config File
<?xml version="1.0"?>
<configuration>
<appSettings/>
<system.web>
<httpRuntime requestPathInvalidCharacte rs="" requestValidationMode="2.0 " relaxedUrlToFileSystemMapp ing="true" />
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<!--<httpRuntime/>-->
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled ="True"/>
<services>
<service name="SkyTrax.loginReq">
<endpoint address="" behaviorConfiguration="web Behavior" binding="webHttpBinding" bindingConfiguration="" contract="SkyTrax.IloginRe q"/>
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAll Requests=" true"/>
<!-- To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
This has been bother me for a couple days and I can't figure it out. I am trying to create a WCF Webservice with a Post command. This needs to except an xml as a parameter and return a string. When I run my service in the browser i get end point not found. When I run from a test application i get "The remote server returned an error: (404) Not Found." I am really not sure what I am doing wrong or how I should be calling this service. My code is below:
Imports System.ServiceModel
Imports System.ServiceModel.Web
Imports System.IO
' NOTE: You can use the "Rename" command on the context menu to change the interface name "IloginReq" in both code and config file together.
<ServiceContract()>
Public Interface IloginReq
<OperationContract(Name:="
<WebInvoke(Method:="POST",
Function PostSampleMethod(data As Stream) As String
End Interface
Imports System.Web.Script.Serializ
Imports System.IO
Imports System.Xml
<AspNetCompatibilityRequir
Public Class loginReq
Implements IloginReq
Public Function PostSampleMethod(data As Stream) As String Implements IloginReq.PostSampleMethod
' convert Stream Data to StreamReader
Dim reader As New StreamReader(data)
' Read StreamReader data as string
Dim xmlString As String = reader.ReadToEnd()
Dim returnValue As String = xmlString
' return the XMLString data
Return returnValue
End Function
End Class
'''Web config File
<?xml version="1.0"?>
<configuration>
<appSettings/>
<system.web>
<httpRuntime requestPathInvalidCharacte
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0"/>
<!--<httpRuntime/>-->
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment
<services>
<service name="SkyTrax.loginReq">
<endpoint address="" behaviorConfiguration="web
</service>
</services>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAll
<!-- To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
So you are trying to use it as a restful API?
ASKER
Yes we have to use a restful web service with a post command to interface with another companies system. I wouldn't be using this method if I had any other options as I am very new to restful webservices. Basically we have it setup on IIS ready to go and if I use a WebGet instead of WebInvoke it works, but we have to use WebInvoke with a "Post"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.