Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP.NET + FileMaker, HTTP GET and POST problems

Status
Not open for further replies.
Jul 10, 2008
32
US
Warning, I'm an extreme newbie to this stuff, I'm actually an intern so I'm still learning. I wasn't sure who would be more likely to know how to help me, FileMaker experts or ASP.NET experts, so I posted in both forums.

I am trying to send GET and POST requests to a web-enabled FileMaker database using a ASP.NET web service. I got my Find function working, and I am now able to run queries against the database using HTTP GET and the results are returned to me as XML. However, I am still having a problem with adding new records. I can add a new record with GET, but not POST. From my understanding, URIs have a length limit, and I've read that POST can be used in place of GET to avoid this limitation. I tried implementing a POST function based on sample code I saw, but I have a feeling I did it completely wrong. Like I said, I'm new to web services so forgive me.

This code works:
Code:
<WebMethod()> _
    Public Function Find() As String
        Dim uri As New Uri("[URL unfurl="true"]http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-dso_xml&field1=value1&-find")[/URL]
        Dim credentials As NetworkCredential

        If (uri.Scheme = uri.UriSchemeHttp) Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Get
            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            response.Close()
            Return xml
        End If
    End Function

And this code works:
Code:
<WebMethod()> _
<WebMethod()> _
    Public Function AddRecordWithHTTPGet() As String
        Dim uri As New Uri("[URL unfurl="true"]http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-fmp_xml&field2=value2&-new")[/URL]

        Dim credentials As NetworkCredential

        If (uri.Scheme = uri.UriSchemeHttp) Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Get
            Dim response As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(response.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            response.Close()
            Return xml
        End If
    End Function

This code DOESN'T work:
Code:
<WebMethod()> _
    Public Function AddRecordWithHTTPPost()
        ' I get a "Format file not found" error:
        Dim uri As New Uri("[URL unfurl="true"]http://localhost:8888/FMPro?-db=TABLENAME.fp5&-format=-fmp_xml&-lay=webdown")[/URL]
        Dim param1 As String = "field3=value3&-new"

        Dim credentials As NetworkCredential

        If uri.Scheme = uri.UriSchemeHttp Then
            Dim request As HttpWebRequest = HttpWebRequest.Create(uri)
            credentials = New NetworkCredential("", "password")
            request.Credentials = credentials
            request.Method = WebRequestMethods.Http.Post
            request.ContentLength = param1.Length
            request.ContentType = "application/x-[URL unfurl="true"]www-form-urlencoded"[/URL]

            Dim writer As New StreamWriter(request.GetRequestStream)
            writer.Write(param1)
            writer.Close()

            Dim oResponse As HttpWebResponse = request.GetResponse()
            Dim reader As New StreamReader(oResponse.GetResponseStream())
            Dim xml As String = reader.ReadToEnd()
            oResponse.Close()
            Return xml
        End If

    End Function

I think I read somewhere that adding FileMaker records can only be done with GET. Yet, when I view the web-enabled database in the browser and click "New record", a blank form comes up and when I left-click and select "View source code", FORM METHOD=POST is in the code. So there must be a way to do it in ASP.NET. Does anyone know how?

FWI, once I get this working, I will be parsing XML sent from a VB.NET app and transferring it to a web-enabled FileMaker database. What I'm doing now is just testing, because I obviously can't do the rest until I get the POST/GET functions working.
 
is this throwing an exception? if so what kind, if not how is it "not working". saying "it doesn't work" means nothing.

I would start by separating the web logic from the domain logic.
1. it seperates concerns.
2. you can then begin unit testing (nunit, mbunit) your logic.

this will help isolate the problem. as you can determine whether it's a web service issue, or an issue with your FileMaker logic.

I would also recommend subscribing to the follow blogs
codebetter.com
lostechies.com
jpboodhoo.com
ayende.com

code better and lostechies are aggregate blogs. All these developers use methodologies (S.O.L.I.D. and Test Driven Development) that MS does a poor job of demonstrating. If you pick up these habits over MS' you will produce code that is
1. adaptable to change
2. easily testable in an automated fashion
3. easy for other developers to understand (given they understand SOLID design principles).

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
No exception is thrown, but FileMaker generates an error that is returned to me in the String xml variable. This is the xml that is returned:
Code:
<?xml version="1.0" encoding="utf-8" ?> 
<anyType xmlns:q1="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] d1p1:type="q1:string" xmlns:d1p1="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xmlns="[URL unfurl="true"]http://www.lifenethealth.org"><HTML>[/URL] <HEAD> <TITLE>Format File Not Found</TITLE> <SCRIPT LANGUAGE="JavaScript" SRC="/FMRes/FMP-IWPErr.js"></SCRIPT> <SCRIPT LANGUAGE="JavaScript"> err.title = "Format File Not Found"; err.mssg = "No format file was specified."; </SCRIPT> </HEAD> <BODY BGCOLOR="#ffffff" onLoad="err.display()"> <NOSCRIPT> <P ALIGN=CENTER><CENTER> <TABLE BORDER=1 WIDTH=450 HEIGHT=170 bgcolor=FFFFFF> <TR> <TD> <P><TABLE BORDER=0 WIDTH="100%" HEIGHT=200> <TR> <TD COLSPAN=2 WIDTH=395 HEIGHT=30> <P ALIGN=CENTER><CENTER> <TABLE BORDER=0 WIDTH="99%" HEIGHT=15> <TR> <TD bgcolor="#cc3333" WIDTH="80%"> <P ALIGN=CENTER><B><FONT SIZE="+1" COLOR="#FFFFFF">Format File Not Found</FONT></B> </TD> </TR> </TABLE> </CENTER> </TD> </TR> <TR> <TD VALIGN=top WIDTH=15 HEIGHT=120><P></TD> <TD VALIGN=top WIDTH=380 HEIGHT=120> <BR> <P>No format file was specified.</P> <P>Click the <B>Back</B> button on your browser to return to the view you were working on. </TD> </TR> <TR> <TD WIDTH=15 HEIGHT=18><P></TD> <TD VALIGN=top WIDTH=380 HEIGHT=18><P ALIGN=RIGHT></TD> </TR> </TABLE> </TD> </TR> </TABLE> </CENTER></P> </NOSCRIPT> </BODY> </HTML></anyType>

"Format File Not Found" error. This is obviously a FileMaker error...however, I feel like my POST function may not be done correctly and may be causing the FM error, which is why I decided to post to the ASP.NET forum as well.
 
Nevermind, I figured out how to perform the POST. :) The problem was with the URI. I did not have it formatted correctly...I didn't know the URI can only contain up to the question mark, and everything else must be contained in the POST body. I also found that even though my FM database has only a password (no username), I had to include a dummy username in the credentials, otherwise I could not authenticate. As long as I had at least one character in place of "username" it would work.

Thought I'd share the solution in case anyone else ever runs into this problem.

Now I'm working on the XML part...parsing XML sent to my web service via HTTP POST, then POSTing the data back to a FileMaker database.
 
load the xml into either an xmlreader or xmldocument object and parse as necessary.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top