2011-12-16 5 views
0

他の投稿で同様の質問をしていますが、私の質問にはあまり答えないと思います。これは十分な情報ではない、書式設定がオフである、またはそれ以外の場合はお詫び申し上げます。私の初めての投稿。asp.net WebサーバーをiPhoneに接続する方法

私のグループは基本的に、私たちのSQLサーバーデータベースとのインターフェイスが必要なiPhoneアプリケーションを実行しています。しかし彼らはお互いに直接話すことができないので、XMLを受け入れ、明らかにJSODを出力する必要があるasp.net媒体を実装しています。現在私は "作業中の"コード(コード内のテスト文字列)で書かれた.asmxを持っています。今はiPhoneからXMLを受け入れようとしています。私は彼の最後(iPhone)または私の最後(.asmx)のいずれかで何かが欠けているように感じる。うまくいけば、あなたの明るい精神は、私たちの複合的な研究のために私を埋めることができます....私は何か不足しているtheresを感じる。たぶん私は間違っていると私は私たちのものを一緒に持っている私は素晴らしいだろう。

明らかに、これは情報を接続して転送するために彼が最後に(彼の研究によれば)必要とするすべてです。明らかにそれが.asmxではないが、拡張機能は重要ではないだろうか?ここで NSURL *url = [NSURL URLWithString:@"http://myurl.com/RequestHandler.ashx"];


は私の.asmxを持っているコードは、現在

using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.Services; 
    using System.Xml.Linq; 

    namespace Outbreak_Mobile 
    { 
     [WebService(Namespace = "http://OutbreakMobile.net/")] 
     [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
     [System.ComponentModel.ToolboxItem(false)] 
     // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
     // [System.Web.Script.Services.ScriptService] 
     public class Service1 : System.Web.Services.WebService 
     { 
      [WebMethod (Description="To intake an xml package from iPhone and store it")] 
      public string iPhoneLocation(string xml) 
      { 
       //test string to output to screen 
       string location = null; 

       //test string of xml to be parsed 
       //will be converting next line to parse input xml 
       //string xml = @"<Player> 
      //     <Latitude>42.13245465</Latitude> 
      //     <Longitude>11.11111111</Longitude> 
       //    </Player>"; 

       //line to parse document 
       //xdocument doc = xdocument.parse(incoming xml) 
       XDocument doc = XDocument.Parse(xml); 

       //grabs the information inside <player> tags 
       XElement loc = doc.Elements("Player").SingleOrDefault(); 

       if (loc != null) 
       { 
        var lat = (double)loc.Element("Latitude"); 
        var lng = (double)loc.Element("Longitude"); 

        location = "Lat: " + lat + '\n' + "Long: " + lng; 
       } 

       //this is what puts out to the screen 
       return location; 

      } 
     } 
    } 

文字列「場所」の出力(肉がであるところの機能があることに注意)で機能テストのためだけでしたパッケージを正しく受け取っていることがわかったら変更されます。お互いにつながるためには何が欠けていますか?

ありがとうございました!

答えて

0

NSURLオブジェクトを作成しました。これで、そのURLからデータをダウンロードするためにNSURLConnectionを作成する必要があります。

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

そして、あなたは接続からちょうどNSStringの-initWithData使用しましたNSDataオブジェクト転送する:エンコーディング:メソッドを。

+0

asp.net側はどうですか?それはアイフォーンからデータを取り込むために何かが欠けている?私はそれが関数に入る前にそれをどうにかして消費すると推測しています...迅速な返信btwをありがとう:) –

+0

私はASPについて知っているすべてResponse.Write()です。その部分でお手伝いできない、ごめんなさい:( –

+0

良い、ありがとう、答え:)他の人がasp.netが欠けていることを知っていたらうれしいです! –