weblivz

I have two methods in my .svc file hosted in IIS.

One uses WebGet and works great - the other using WebInvoke with Method="POST" and when i create a simple test client to query it, i get a 404.

Does anyone know what may be going on here I can click on the URL it is going to i the POST and i get "There are no endpoints" (due to the fact there is no default GET URITemplate match) - so the page is there.

I also uses my client code to successfully request a .aspx page in the exact same folder with no problems.

Any ideas much appreciated!!

regards,

steven

http://livz.org



Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

James.Zhang - MSFT

Maybe it is because the UriTemplate you specified in the method does not match incoming url




Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

Hi James. Appreciate some help to resolve this one.

I have following contract defined at my endpoint which needs POST, another GET method works fine.

[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = " m=Register&username={username}&password={password}&token={token}")]
void Register(string username, string password, string token);

I can create the following test html page.

<html>
<form action="
http://dev/services/api/my.Registration/default.svc" method="post">
<input type=text name="m" value="Register" />
<br/>
<input type=text name="username" value="test"/>
<br/>
<input type=text name="password" value="test" />
<br/>
<input type=text name="token" value="test" />
<br/>
<input type=submit />
</form>
</html>

I get the following in my IIS log.

09:58:27 192.168.7.3 GET /services/api/my.Registration/default.svc 307
09:58:27 192.168.7.3 GET /services/api/my.Registration/default.svc 405
09:59:24 192.168.7.3 POST /services/api/my.Registration/default.svc 404

As you can see I make the GET query successfully, but the POST to the same page fails - not even with a 405, but a 404 ! You rightly point out this could be something i am doing that is not mapping the template... i have tried quite a few variations with no success. Any help here would be very much appreciated.

Unfortunately the samples don't deal with interop of REST services so i don't know whether i am doing something wrong or whether there is some problem and hence no sample.

Regards,

Steven

http://dev/services/api/my.Registration/default.svc" method="post">
<input type=text name="m" value="Register" />
<br/>
<input type=text name="username" value="test"/>
<br/>
<input type=text name="password" value="test" />
<br/>
<input type=text name="token" value="test" />
<br/>
<input type=submit />
</form>
</html>

I get the following in my IIS log.

09:58:27 192.168.7.3 GET /services/api/my.Registration/default.svc 307
09:58:27 192.168.7.3 GET /services/api/my.Registration/default.svc 405
09:59:24 192.168.7.3 POST /services/api/my.Registration/default.svc 404

As you can see I make the GET query successfully, but the POST to the same page fails - not even with a 405, but a 404 ! You rightly point out this could be something i am doing that is not mapping the template... i have tried quite a few variations with no success. Any help here would be very much appreciated.

Unfortunately the samples don't deal with interop of REST services so i don't know whether i am doing something wrong or whether there is some problem and hence no sample.

Regards,

Steven

http://livz.org





Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

Btw - if i an an empty template (i.e. post no actual data) it does actually work - but kinda limits what its point in life is.

When working with POST should I *never* specify a URI template in the WebInvoke Should i always use the template BindBy... stuff to do the mapping It doesn't seem to like two methods with an empty template URI so there musyt be more to it....

steven

http://livz.org





Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

A WCF trace throws up an error that the service expected a format of "Xml" or "JSON" and instead got an unexpected Raw message format.

Can I not just make an HTTP POST Do i need to wrap as an Xml formatted query Or maybe i need to set something somewhere.

regards,

setven

http://livz.org




Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

Christian Weyer

I guess it is not possible - at least I have found no way how to do it.






Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

Thanks Christian - glad it is not just me Smile

I guess this must be a bug... and backs up my previous post about the samples being too light (especailly the REST samples which avoid anything slightly complex) - and they were only released a week ago.

James - did you get anything more on this

steven
http://livz.org




Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

Christian Weyer

Can you send me your sample to look at






Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

I also get 403 Forbidden when i try to use PUT or DELETE.

I will wrap up the sample and post... it's very lightweight, so either something is wrong in the framework ... or i have screwed something obvious up.

Regards,
Steven
http://livz.org




Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

For anyone else also interested, here are some code snippets.

default.svc
<%@ ServiceHost Factory="System.ServiceModel.Web.WebServiceHostFactory" Language="C#" Debug="true"
Service="REST.Registration"%>


IRESTRegistration.cs
using System.ServiceModel;
using System.ServiceModel.Web;

namespace REST
{
[ServiceContract]
public interface IRegistration
{
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = " m=Register&username={username}&password={password}&token={token}")]
void Register(string username, string password, string token);

[OperationContract]
[WebGet(UriTemplate = " m=IsVerified&username={username}")]
bool IsVerified(string username);
}
}


Registration.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;


namespace REST
{
public class Registration : IRegistration
{
#region IRegistration Members

public void Register(string username, string password, string token)
{
//do something
}

public bool IsVerified(string username)
{
return true;
}

#endregion
}
}


Web.config (snippet)

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="RegistrationBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="RegistrationBehavior" name="Registration">
<endpoint address="" binding="webHttpBinding" contract="IRegistration" />
</service>
</services>
</system.serviceModel>



TestRESTAPI
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Net;
using System.IO;

namespace TestRESTAPI
{
/// <summary>
/// Summary description for TestRegistrationAPI
/// </summary>
[TestClass]
public class TestRegistrationAPI
{
#region Additional test attributes
#endregion

#region IRegistration Members

[TestMethod]
public void Register()
{
//set the data
ASCIIEncoding enc = new ASCIIEncoding();
string datatext = "m=Register&username=test&password=test&token=test";
byte[] data = enc.GetBytes(datatext);

//HTTP POST query
WebRequest request = HttpWebRequest.Create("http://localhost/WebSite/default.svc");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

Stream datasteam = request.GetRequestStream();
datasteam.Write(data, 0, data.Length);
datasteam.Close();

WebResponse response = request.GetResponse();
}

[TestMethod]
public void IsVerified()
{
//HTTP GET query
WebRequest request = HttpWebRequest.Create("http://localhost/WebSite/default.svc m=IsVerified&username=steven");
request.Method = "GET";
WebResponse response = request.GetResponse();

StreamReader rdr = new StreamReader(response.GetResponseStream());

Assert.AreEqual<string>("<boolean xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">true</boolean>", rdr.ReadToEnd());
}

#endregion
}
}






Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

T.R.Vishwanath - MSFT

We donĄ¯t support RAW HTTP POST (that sends a HTTP request with content type 'application/x-www-form-urlencoded' out of the box unless you treat the request body as a Stream in your operation contract.

So if you change the Register method contract to

void Register(Stream s)

and parse the body into a NameValueCollection using HttpUtility.ParseQueryString in your Register implementation, it should work fine.

That said, Orcas RTM will ship with an extensibility sample that shows how you can treat 'application/x-www-form-urlencoded' content as a NameValueCollection in your operation contract.

Thanks

Vish






Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

weblivz

Thanks.

This is unfortunate as i suspect people will want to change between GET and POST easily - again i refer to the Flickr API which is probably the best and easist to follow on the web. I do this this lack of (direct) support needs to be highlighted more in the doco as i think most people will assume this is the default.

FWIW, i noticed the August WCF "Xml samples" here actually use JSON (a mistake ). Is there a reason for this Is there some Xml samples

steven

http://livz.org





Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

Jitesh


Hi

I was reading this post , and thought it might be useful to post to this thread my problem

my Uritemplate is like that

xml/users/{userId}/postComment

my OperationContract is like

PostCommentsXml(string UserId, Stream stream);

we used Stream exactly for same reason, we wanted ContentType = "application/x-www-form-urlencoded

REST call works fine as we expected and no issue with it
, but when we try to Browse SVC file we get exception

as per this article

http://msdn2.microsoft.com/en-us/library/ms789010.aspx

it says

To stream data

<!--[if !supportLists]-->1. <!--[endif]-->To stream data, the OperationContract for the service must satisfy two requirements:

<!--[if !supportLists]-->1. <!--[endif]-->The parameter that holds the data to be streamed must be the only parameter in the method. For example, if the input message is the one to be streamed, the operation must have exactly one input parameter. Similarly, if the output message is to be streamed, the operation must have either exactly one output parameter or a return value.

<!--[if !supportLists]-->2. <!--[endif]-->At least one of the types of the parameter and return value must be either Stream, Message, or IXmlSerializable



we surely need to support ContentType = "application/x-www-form-urlencoded as well as
we need to support Parameters in our UriTemplate xml/users/{userId}/postComment

is there any workaround for this or any alternate type for Stream where I can pass parameters as well

It would be really help if I get reply to this post

Regards
Jitesh





Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

Jitesh

I'm trying to grab the contents of a Stream on PUT or POST using the Message object. Does anyone know how to do that My services is using REST, and the content-type is going to be a application/x-www-form-urlencoded.





Re: Windows Communication Foundation (Indigo) 404 errors with HTTP POST using WebInvoke on Orcas Beta 2

Jitesh

I'm trying to grab the contents of a Stream on PUT or POST using the Message object. Does anyone know how to do that My services is using REST, and the content-type is going to be a application/x-www-form-urlencoded.

so lets say we have a call thats goes like this:

[OperationMethod]
[WebInvoke(Method = "POST", UriTemplate = "id")]
void AddId(Stream stream)

our implementation code will take the stream and pull out all data that is valid for this post. WCF conveniently propogates the HTTP Body into the Stream parameter if the request has a content-type of 'application/x-www-form-urlencoded', per the article quoted. My desire is to be able to do what WCF does behind the scenes. The reason i would like to be able to extract the Stream from the Message object is because i am doing this logic in the Channel layer. In the Channely layers, WCF hasn't converted the http body into a Stream yet. I essentially want to do it myself.

any response would be appreciated

Regards

Jitesh