Solved

Having problems creating WCF web service with Post command

Posted on 2014-02-13
4
890 Views
Last Modified: 2014-02-18
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:="PostSampleMethod")>
  <WebInvoke(Method:="POST", UriTemplate:="PostSampleMethod/[New]", ResponseFormat:=WebMessageFormat.Xml, RequestFormat:=WebMessageFormat.Xml, BodyStyle:=WebMessageBodyStyle.Bare)> _
    Function PostSampleMethod(data As Stream) As String

End Interface

Imports System.Web.Script.Serialization
Imports System.IO
Imports System.Xml

<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.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 requestPathInvalidCharacters="" requestValidationMode="2.0"  relaxedUrlToFileSystemMapping="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="webBehavior" binding="webHttpBinding" bindingConfiguration="" contract="SkyTrax.IloginReq"/>
      </service>
    </services>
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--screen shot of service call        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>
0
Comment
Question by:skyzipper
  • 2
4 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39856590
So you are trying to use it as a restful API?
0
 

Author Comment

by:skyzipper
ID: 39856604
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"
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 400 total points
ID: 39857467
Try removing the uritemplate and see if it works.


Tutorial here

http://www.codeproject.com/Articles/255684/Create-and-Consume-RESTFul-Service-in-NET-Framewor
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 100 total points
ID: 39858219
Since you are using VS 2012, why don't you use Web API? Working with REST is much easier in Web API than in WCF. There are several tutorials on the official ASP.NET website.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Where to begin studying? 5 66
crm development 2 37
Visual Studio: built-in keystroke automation 2 24
Open a word document 23 15
While working on Silverlight and WCF application, I faced one issue where fault exception occurred at WCF operation contract is not getting propagated to Silverlight client. So after searching net I came to know that it was behavior by default for s…
Here I am going to explain creating proxies at runtime for WCF Service. So basically we use to generate proxies using Add Service Reference and then giving the Url of the WCF service then generate proxy files at client side. Ok, what if something ge…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now