{"id":376,"date":"2011-08-07T00:36:07","date_gmt":"2011-08-06T15:36:07","guid":{"rendered":"http:\/\/redwing.moo.jp\/cocoa\/?p=376"},"modified":"2011-08-07T00:36:07","modified_gmt":"2011-08-06T15:36:07","slug":"ios-%e3%83%87%e3%83%90%e3%82%a4%e3%82%b9%e3%81%8b%e3%82%89wcf%e3%82%b5%e3%83%bc%e3%83%90%e3%81%b8%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%82%92%e3%82%a2%e3%83%83%e3%83%97%e3%83%ad%e3%83%bc%e3%83%89","status":"publish","type":"post","link":"https:\/\/redwing.moo.jp\/cocoa\/archives\/376","title":{"rendered":"iOS \u30c7\u30d0\u30a4\u30b9\u304b\u3089WCF\u30b5\u30fc\u30d0\u3078\u30d5\u30a1\u30a4\u30eb\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>WCF\u30b5\u30fc\u30d0\u5074 C#\u30d7\u30ed\u30b0\u30e9\u30e0<br \/>\nWCF \u3067\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3001\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306a\u3069\u306f\u9069\u5f53\u306b\u8a2d\u5b9a\u3057\u3066\u304a\u304f\u3002<\/p>\n<p><strong>\u516c\u958b\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u5b9a\u7fa9<\/strong><\/p>\n<pre lang=\"csharp\" line=\"1\">\r\n  [ServiceContract(Namespace = \"http:\/\/My.WCF.Samples\")]\r\n  public interface IService1\r\n  {\r\n    [OperationContract]\r\n    [WebInvoke(Method = \"POST\", UriTemplate = \"UploadFile\/{fileName}\")]\r\n    string UploadFile(string fileName, Stream fileContents);\r\n  }\r\n<\/pre>\n<p><strong>\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3055\u308c\u305f\u30d5\u30a1\u30a4\u30eb\u30c7\u30fc\u30bf\u3092\u4fdd\u5b58\u3059\u308b<\/strong><br \/>\n\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304b\u3089\u53d7\u4fe1\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u30c7\u30fc\u30bf\u3092 c:\u00a5 \u76f4\u4e0b\u306b\u4fdd\u5b58\u3059\u308b<\/p>\n<pre lang=\"csharp\" line=\"1\">\r\nnamespace HelloWCF2\r\n{\r\n  public class Service1 : IService1\r\n  {\r\n    public string UploadFile(string fileName, Stream fileContents)\r\n    {\r\n        Console.WriteLine(\"received file name : {0}\", fileName);\r\n        byte[] buffer = new byte[1000000];\r\n        int bytesRead, totalBytesRead = 0;\r\n        do\r\n        {\r\n            bytesRead = fileContents.Read(buffer, 0, buffer.Length);\r\n            totalBytesRead += bytesRead;\r\n        } while (bytesRead > 0);\r\n        Console.WriteLine(\"Uploaded file {0} with {1} bytes\", fileName, totalBytesRead);\r\n\r\n        System.IO.FileStream fs = new System.IO.FileStream(@\"C:\\myphoto.png\",\r\n                                                            System.IO.FileMode.Create,\r\n                                                            System.IO.FileAccess.Write);\r\n        fs.Write(buffer, 0, totalBytesRead);\r\n        fs.Close();\r\n\r\n        return \"\u753b\u50cf\u3092\u53d7\u4fe1\u3057\u307e\u3057\u305f\";\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<p>iOS \u30c7\u30d0\u30a4\u30b9\u5074 objective-c \u30d7\u30ed\u30b0\u30e9\u30e0<br \/>\n<strong>iOS \u30c7\u30d0\u30a4\u30b9\u304b\u3089 .png \u753b\u50cf\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30d1\u30bf\u30fc\u30f31 (ASIFormDataRequest \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408)<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\r\n    \/\/ PNG\u753b\u50cf\u3092 WCF \u30b5\u30fc\u30d0\u3078\u9001\u4fe1\u3059\u308b\r\n    \/\/ 1. ASIFormDataRequest \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\r\n    NSURL *url = [NSURL URLWithString:@\"http:\/\/192.168.x.x:8000\/WCFSampleService\/HelloWCF\/UploadFile\/myphoto.png\"];\r\n    request_ = [ASIFormDataRequest requestWithURL:url];\r\n    \r\n    [request_ setPostValue:@\"myphoto1.png\" forKey:@\"fileName\"];\r\n\r\n    UIImage *image = [UIImage imageNamed:@\"myphoto1.png\"];\r\n    NSData* imageData = [[NSData alloc] initWithData:UIImagePNGRepresentation(image)];\r\n    [request_ appendPostData:imageData];\r\n    \r\n    [request_ setRequestMethod:@\"POST\"];\r\n    \r\n    [request_ setDidFinishSelector:@selector(requestFinished:)];\r\n    [request_ setDidFailSelector:@selector(requestFailed:)];\r\n    [request_ setDelegate:self];\r\n    [request_ startAsynchronous];\r\n<\/pre>\n<p><strong>iOS \u30c7\u30d0\u30a4\u30b9\u304b\u3089 .png \u753b\u50cf\u3092\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3059\u308b\u30d1\u30bf\u30fc\u30f32 (NSURLConnection \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408)<\/strong><\/p>\n<pre lang=\"objc\" line=\"1\">\r\n    \/\/ 2. NSURLConnection \u3092\u4f7f\u7528\u3059\u308b\u5834\u5408\r\n    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];\r\n    [request setURL:[NSURL URLWithString:@\"http:\/\/192.168.0.8:8000\/WCFSampleService\/HelloWCF\/UploadFile\/myphoto.png\"]];\r\n    [request setHTTPMethod:@\"POST\"];\r\n    \r\n    NSMutableData *postBody = [NSMutableData data];\r\n    UIImage *image = [UIImage imageNamed:@\"myphoto1.png\"];\r\n    NSData* imageData = [[NSData alloc] initWithData:UIImagePNGRepresentation(image)];\r\n    [postBody appendData:[NSData dataWithData:imageData]];\r\n    [request setHTTPBody: postBody];\r\n\r\n    \/\/ \u975e\u540c\u671f\u901a\u4fe1\r\n    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];\r\n    if (conn == nil) {\r\n        \/\/ \u30a8\u30e9\u30fc\u51e6\u7406\r\n    }\r\n<\/pre>\n<a href=\"https:\/\/twitter.com\/redwing1300?ref_src=twsrc%5Etfw\" class=\"twitter-follow-button\" data-size=\"large\" data-show-count=\"false\">Follow @redwing1300<\/a><script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content --><div id=\"redwi-53948257\" class=\"redwi- redwi-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-9652476346722993\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:block;\" data-ad-client=\"ca-pub-9652476346722993\" \ndata-ad-slot=\"\" \ndata-ad-format=\"auto\"><\/ins>\n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>WCF\u30b5\u30fc\u30d0\u5074 C#\u30d7\u30ed\u30b0\u30e9\u30e0 WCF \u3067\u306e\u30a8\u30f3\u30c9\u30dd\u30a4\u30f3\u30c8\u3001\u30d0\u30a4\u30f3\u30c7\u30a3\u30f3\u30b0\u3001\u30b3\u30f3\u30c8\u30e9\u30af\u30c8\u306a\u3069\u306f\u9069\u5f53\u306b\u8a2d\u5b9a\u3057\u3066\u304a\u304f\u3002 \u516c\u958b\u30a4\u30f3\u30bf\u30d5\u30a7\u30fc\u30b9\u5b9a\u7fa9 [ServiceContract(Namespace = &#8220;http:\/\/My. &hellip; <a href=\"https:\/\/redwing.moo.jp\/cocoa\/archives\/376\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-376","post","type-post","status-publish","format-standard","hentry","category-cocoa"],"_links":{"self":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/comments?post=376"}],"version-history":[{"count":19,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/376\/revisions"}],"predecessor-version":[{"id":395,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/posts\/376\/revisions\/395"}],"wp:attachment":[{"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/media?parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/categories?post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/redwing.moo.jp\/cocoa\/wp-json\/wp\/v2\/tags?post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}